O'Reilly logo

RabbitMQ Cookbook by Sigismondo Boschi, Gabriele Santomaggio

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to let queues expire

In this third case, the TTL is not related to messages anymore, but to queues. This case is a perfect fit to manage server restarts and updates. The RabbitMQ drops the queue as soon as the TTL has elapsed, that is, after the last consumer has stopped consuming messages.

As in the previous TTL-related recipes, you can find the Producer.java, Consumer.java, and GetOne.java files in Chapter02/Recipe03/Java/src/rmqexample.

Getting ready

To use this recipe, we need to set up the Java development environment as indicated in the Introduction section of Chapter 1, Working with AMQP.

How to do it...

As in the previous example, the extension regards only Consumer.java:

  1. Create or declare the exchange using the following code:
    channel.exchangeDeclare(exchange, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required