The client may fail to connect, resulting in the queue being left behind, and a large number of remaining queues will affect the performance of the instance. RabbitMQ provides three methods to auto delete queues:
· Set TTL policy in the queue: For example, if the TTL policy is set to 28 days, the queue will be deleted if it is not used for 28 days.
· Use auto-delete queue: The auto-delete queue is deleted when the last consumer exits or the channel/connection closes (or the TCP connection to the server is lost).
· Use exclusive queue: The exclusive queue can only be used in the connection in which it was created, and is deleted when this connection is closed or disappears.
Here's how to set it up:
boolean exclusive = true;
boolean autoDelete = true;
channel.queueDeclare(QUEUENAME, durable, exclusive, autoDelete, arguments);