使用 AMQPNetLite.Core 2.4.6 的消息组和独占消费者

问题描述 投票:0回答:1

我正在尝试利用 ActiveMQ Artemis 的消息组 (https://activemq.apache.org/message-groups) 和 Exclusive Consumer (https://activemq.apache.org/exclusive-consumer) 功能使用 .NET Core AMQP NuGet 包 AMQPNetLite.Core。但是,AMQPNetLite 的文档未提供有关此主题的信息。任何有关此事的帮助将不胜感激。

我尝试与

Exclusive
创建连接,如下所示。但在 ActiveMQ Artemis Web 控制台中,我没有看到队列上设置的
Exclusive
属性。

 static async Task Main(string[] args)
        {
            string url = (args.Length > 0) ? args[0] :
                "amqp://admin:[email protected]:5672";
            string source = (args.Length > 1) ? args[1] : "examples";
            int count = (args.Length > 2) ? Convert.ToInt32(args[2]) : 10;

            ConnectionFactory factory = new ConnectionFactory();
            Address peerAddr = new Address(url);
            Amqp.Types.Fields properties= new Amqp.Types.Fields
            {
                { new Symbol("Exclusive"), true }
            };
            Connection connection = await factory.CreateAsync(peerAddr, new Open { ContainerId=Guid.NewGuid().ToString(), Properties=properties });
            Session           session = new Session(connection);
            ReceiverLink receiver = new ReceiverLink(session, "recv-1", source);

            while (true)
            {
                Message msg = receiver.Receive();
                receiver.Accept(msg);
                Console.WriteLine("Received: " + msg.Body.ToString());
            }


        }

c# amqp activemq-artemis
1个回答
0
投票

独占队列是特定于代理的功能。它不是 AMQP 规范的一部分,据我所知,它没有扩展,因此您无法在客户端上配置排他性。

如文档中所述,您可以静态地将队列配置为独占,例如:

<address name="examples">
   <multicast>
      <queue name="exampleQueue" exclusive="true"/>
   </multicast>
</address>

或者您可以使用适用于一个或多个地址上的所有队列的

address-setting
,例如:

<address-setting match="examples">
   <default-exclusive-queue>true</default-exclusive-queue>
</address-setting>

既然你正在使用

multicast
,这就是我推荐的,尽管在大多数多播用例中,每个队列只有1个消费者,所以不清楚为什么你通常需要这个。

© www.soinside.com 2019 - 2024. All rights reserved.