代码之家  ›  专栏  ›  技术社区  ›  André

如何从客户端设置路由类型activemq artemis

  •  0
  • André  · 技术社区  · 6 年前

    我正试图以你好世界为例。有了常规的ActiveMQ,它是有效的,但是ActiveMQ-Artemis让我头疼。我想有些配置我做得不正确。地址是通过多播路由生成的。我想我需要单播(队列路由)。

    以下代码段不适用于ActiveMQ的Artemis版本。有没有可能我要做的?我想自动创建一个持久队列。

    public class SimpleAmqpTest
        {
            [Fact]
            public async Task TestHelloWorld()
            {
                Address address = new Address("amqp://guest:guest@localhost:5672");
                Connection connection = await Connection.Factory.CreateAsync(address);
                Session session = new Session(connection);
    
                Message message = new Message("Hello AMQP");
    
                var target = new Target
                {
                    Address = "simple-queue",
                    Durable = 1,
                };
    
                SenderLink sender = new SenderLink(session, "sender-link", target, null);
                await sender.SendAsync(message);
    
                ReceiverLink receiver = new ReceiverLink(session, "receiver-link", "simple-queue");
                message = await receiver.ReceiveAsync();
                receiver.Accept(message);
    
                await sender.CloseAsync();
                await receiver.CloseAsync();
                await session.CloseAsync();
                await connection.CloseAsync();
            }
        }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   André    6 年前

    Capabilities = new Symbol[] { new Symbol("queue") }

    public async Task TestHelloWorld()
            {
                //strange, works using regular activeMQ and the amqp test broker from here: http://azure.github.io/amqpnetlite/articles/hello_amqp.html
                //but this does not work in ActiveMQ Artemis
                Address address = new Address("amqp://guest:guest@localhost:5672");
                Connection connection = await Connection.Factory.CreateAsync(address);
                Session session = new Session(connection);
    
                Message message = new Message("Hello AMQP");
    
                Target target = new Target
                {
                    Address = "q1",
                    Capabilities = new Symbol[] { new Symbol("queue") }
                };
    
                SenderLink sender = new SenderLink(session, "sender-link", target, null);
                sender.Send(message);
    
                Source source = new Source
                {
                    Address = "q1",
                    Capabilities = new Symbol[] { new Symbol("queue") }
                };
    
                ReceiverLink receiver = new ReceiverLink(session, "receiver-link", source, null);
                message = await receiver.ReceiveAsync();
                receiver.Accept(message);
    
                await sender.CloseAsync();
                await receiver.CloseAsync();
                await session.CloseAsync();
                await connection.CloseAsync();
            }