Search code examples
c#amqpactivemq-artemis

How to create a non durable queue in ActiveMQ Artemis?


I have a application in which I want to have 1 durable and 1 non-durable queue in Active MQ Artemis. For connecting to this message bus I use amqpnetlite.

        var source = new Source()
        {
        };

        if (durable)
        {
            source.Address = amqpAddressConverter.GetSubscriberAddress(address, useLoadBalancing);
            source.Durable = 1;
            source.ExpiryPolicy = new Symbol("never");
            source.DistributionMode = new Symbol("copy");
        }
        else
        {
            source.Address = amqpAddressConverter.GetSubscriberAddress(address);
            source.Durable = 0;
            source.ExpiryPolicy = "never";
        }

        var receiverLink = new ReceiverLink(session, linkName, source, null);

So this is my receiver link. As shown I set the Durable uint of the Source which will given into the ReceiverLink.

Because as I saw in the Active MQ Artemis documentation, that the Durable is a boolean but within the amqpnetlite library it is an uint my understanding is that everything over 0 should be true and 0 should be false.

At first the behaviour was very strange: Even when the Aretemis Web interface was shown a queue as durable it would be deleted as soon as no consumer would be connected.

I found this: ActiveMQ Artemis queue deleted after shutdown of consuming client which describes that even durable queues get deleted because of the default behaviour.

So I manipulated the broker.xml and set AUTO-DELETE-QUEUE to false.

Since then the behaviour completly switched: Both (durable = 1 and durable = 0) queues are being still there after the connection disconnected.

So how to create a durable and a non-durable connection correctly?


Solution

  • The Artemis source carries an example in .NET that creates a durable topic subscription and also shows how to later recover it using AmqpNetLite.

    One key thing many folks miss is that your client needs to use a unique container ID analogous to the JMS Client ID concept.

    For Queue specific subscriptions the client should indicate in the link capabilities that it wants a Queue based address created as the default is a multicast Queue which won't behave the same.

    Source source = new Source() {
        Address = address,
        Capabilities = new Symbol[] {"queue"},
    };
    

    vs topic specific source configuration:

    Source source = new Source() {
        Address = address,
        Capabilities = new Symbol[] {"topic"},
    };