Py学习  »  MQ

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

André • 5 年前 • 619 次点击  

我正试图以你好世界为例。有了常规的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();
        }
    }
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/34620
 
619 次点击  
文章 [ 1 ]  |  最新文章 5 年前
André
Reply   •   1 楼
André    5 年前

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();
        }