AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - 自动创建多消费者多播队列

标签 amqp jboss-amq

这个问题是在 .Net 中使用 AMQP 来消费消息。文档推荐使用 amqpnetlite:https://access.redhat.com/documentation/en-us/red_hat_amq/7.0/html-single/using_the_amq_.net_client/index

使用 AMQPNetLite 订阅地址时,将自动创建地址和队列。不过,自动创建的队列始终是“单播”的。我无法自动创建

  • 多播队列
  • 这允许任意数量的消费者。

  • 代码:
    private async Task RenewSession()
    {
        Connect = await Connection.Factory.CreateAsync(new Address("amqp://admin:admin@localhost:5672"), new Open() {ContainerId = "client-1"});
        MqSession = new Session(Connect);
        var receiver = new ReceiverLink(MqSession, DEFAULT_SUBSCRIPTION_NAME, GetSource("test-topic"), null);
        receiver.Start(100, OnMessage);
    }
    
    private Source GetSource(string address)
    {
        var source = new Source
        {
            Address = address,
            ExpiryPolicy = new Symbol("never"),
            Durable = 2,
            DefaultOutcome = new Modified
            {
                DeliveryFailed = true,
                UndeliverableHere = false
            }
        };
        return source;
    }
    

    也许我错过了一些标志?

    最佳答案

    在 AMQP 中,您可以通过设置功能在自动创建队列(任播路由)或主题(多播路由)之间进行选择。

    能力应该是 new Symbol("queue")new Symbol("topic") .

    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");
    
            Target target = new Target
            {
                Address = "q1",
                Capabilities = new Symbol[] { new Symbol("queue") }
            };
    
            SenderLink sender = new SenderLink(session, "sender-link", target, null);
            await sender.SendAsync(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();
        }
    }
    

    看看https://github.com/Azure/amqpnetlite/issues/286 ,代码来自哪里。

    您可以通过设置 default-address-routing-type 来选择默认路由是多播还是任播。在 broker.xml 中,所有内容都记录在 https://activemq.apache.org/artemis/docs/2.6.0/address-model.html

    经纪人的multicastPrefixanycastPrefix未为 AMQP 实现功能。 https://issues.jboss.org/browse/ENTMQBR-795

    关于AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - 自动创建多消费者多播队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51579188/

    相关文章:

    java - 基于 AMQP 的 ServiceBus 丢失重新传递的消息

    javax.jms.JMSSecurityException : User name [null] or password is invalid

    java - Jboss AMQ : Send persistent message from hawtio

    python - 在 python 上从 qpid 获取消息量

    rabbitmq - 是否有可能在 amqp 中获取未路由的消息?

    php - 从 RabbitMQ 队列中检索消息

    Python27 qpid : ImportError: No module named _cproton