[rabbitmq-discuss] Durable subscriptions in Java

Michael Klishin mklishin at gopivotal.com
Fri Feb 7 11:03:51 GMT 2014


On 7 Feb 2014, at 14:42, Tomas Tulka <tomas.tulka at atos.net> wrote:

>> If there are no more messages in the queue
> 
> Yes, but the point is to have a durable subscription.

In AMQP 0-9-1, queues and messages are durable. Consumers are not.

http://www.rabbitmq.com/tutorials/amqp-concepts.html explains this in more detail.

Try leaving your publisher on while consumers are down and watch the queue
grow. Then add a consumer. It should start getting deliveries.

>> It’s impossible to tell what the issue is without seeing your code. 
> 
> Please see the whole class code. RabbitMqDurable.java
> <http://rabbitmq.1065348.n5.nabble.com/file/n33190/RabbitMqDurable.java>  

https://gist.github.com/michaelklishin/0082745ddf31fa951221

You’re using QueueingConsumer and no prefetch limit. This means RabbitMQ indeed
will push messages to the client as fast as possible, and the client will enqueue them
internally in a blocking queue.

Your way to “kill” the consumer only kill the while loop. The consumer still keeps getting deliveries.
In addition, you don’t reset the timer so the "2nd consumer” will be “killed” immediately.

Cancel your consumer properly with Channel#basicCancel and create a new one every time. Use
JDK scheduled executors to periodically cancel and re-add consumers:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

To learn about basic.qos/prefetch, see tutorial 2:
http://www.rabbitmq.com/tutorials/tutorial-two-java.html

MK

Software Engineer, Pivotal/RabbitMQ




More information about the rabbitmq-discuss mailing list