Search code examples
c#amqpactivemq-artemis

MessageGroups and Exclusive Consumer using AMQPNetLite.Core 2.4.6


I'm attempting to the message grouping and exclusive queues features from ActiveMQ Artemis 2.30.0 using the .NET Core AMQP NuGet package, AMQPNetLite.Core. However, the documentation for AMQPNetLite does not provide information on this topic.

I have tried to create connection with Exclusive as below. But in ActiveMQ Artemis web console I don't see the Exclusive attribute set on the queue.

static async Task Main(string[] args)
{
    string url = (args.Length > 0) ? args[0] :
        "amqp://admin:passw0rd@127.0.0.1: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());
    }
}

enter image description here


Solution

  • Exclusive queues is a broker-specific feature. It's not part of the AMQP specification, and as far as I'm aware there's no extension for it so you can't configure exclusivity on the client.

    As noted in the documentation, you can statically configure a queue to be exclusive, e.g.:

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

    Or you can use an address-setting which applies to all the queues on one or more addresses, e.g.:

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

    Since you're using multicast this is what I would recommend, although in most multicast use-cases there's only ever 1 consumer per queue so it's not clear why you would need this in general.

    It's worth noting that message groups and exclusive queues are rarely, if ever, used together. They are both ways to accomplish the same main goal which is the serial (i.e. strictly ordered) consumption of messages, although in slightly different ways. Message groups enforce serial message consumption by pinning a group of message to exactly one consumer. An exclusive queue does the same by allowing only a single consumer to receive messages from the queue.