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, ...

Get RabbitMQ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.