You have several messages in queue and for some reason you need to restart the broker. Once the broker was restarted your messages in the queue are gone.
Here are some points you need to check why messages are not persisting.
Queues declared as durable
Objects such as queues, exchanges needs to be configured as durable in order to survive a restart. Although this will not make the messages that goes through these objects as durable, but next time you restart the broker the queues/exchange are not deleted.
Here are a few ways to create a durable queue:
- Using Management UI -> Queue Tab -> Add Queue -> Make sure Durability is set to Durable
- Using Management Command line tool -> rabbitmqadmin declare queue name=my-new-queue durable=true
- Using Java Client API -> Channel.queueDeclare with durable parameter set to true when declaring a queue
- AMQP's queue.declare
Message delivery mode set to persistent
Message can be published either having a delivery mode set to persistent or transient . Here are a few ways to mark messages as persistent:
- Java client's AMQP.BasicProperties -> Set deliveryMode to 2
- Using Management UI -> Queue Tab -> Select Queue -> Publish Message -> Delivery Mode to Persistent
- AMP's basic -> set delivery-mode to 2
Marking the queue as durable and setting delivery mode to persistent will be able to reduce but does not guarantee no message loss. It is recommended to mix this with rabbit's reliability features.