Configuring RabbitMQ Persistence
By default, messages produced by RabbitMQ producers are stored in the memory. When a node breaks down or restarts, messages are lost. RabbitMQ can persist data during such events for exchanges, queues, and messages.
Persistence means writing messages in the memory to the disk to prevent them from being lost due to exceptions. However, if message persistence is enabled, RabbitMQ performance deteriorates because read and write operations are much slower in disks than in memory. Different from the lazy queue mechanism, a persisted message is stored in both the disk and memory. It is deleted from the memory only when the memory is insufficient.
- Non-persistent queues and exchanges are lost after a restart.
- Non-persistent messages are lost after a restart. (Messages that are sent to persistent queues or exchanges will not automatically become persistent.)
- A message will be lost if the server restarts before the message persistence is complete.
Configuring Exchange Persistence
- On the RabbitMQ management UI
Set durable to true in exchange creation, as shown in Figure 1.
Figure 2 shows a successful configuration.
- On the RabbitMQ console
Configure exchange persistence when creating an exchange, as shown in .
shows a successful configuration.
Configuring Queue Persistence
- On the RabbitMQ management UI
Set durable to true in queue creation, as shown in Figure 3.
Figure 4 shows a successful configuration.
- On the RabbitMQ console
Configure queue persistence when creating a queue, as shown in .
shows a successful configuration.
Configuring Message Persistence
After configuring queue persistence, set MessageProperties to PERSISTENT_TEXT_PLAIN on the client to send persistent messages to the queue.
The following example shows how to configure message persistence on a Java client.
import com.rabbitmq.client.MessageProperties; channel.basicPublish("", "my_queue",MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot