Application Scenario
During the production process, server downtime is inevitable, RabbitMQ is no exception, as it may crash and restart due to some special circumstances. At this time, it is particularly important to restore the data in the message queue, including exchanges, queues, and messages in the queue. RabbitMQ comes with a persistence mechanism, including the persistence of exchanges, queues and messages. The main mechanism of persistence is to write information to disk, and when the RabbtiMQ service is down and restarts, the stored persistence information is read from the disk to restore the data.
Set up Exchange Persistence
(1) Log in to the management console.
(2) Go to the RabbitMQ console.
(3) In the operation column of the instance list page, click Manage in the target instance row.
(4) Click Exchange Management, then click the New button.
(5) Clicking New and the following window will appear, select Yes for "Persistent or Not".
Set up Queue Persistence
(1) Log in to the management console.
(2) Go to the RabbitMQ console.
(3) In the operation column of the instance list page, click Manage in the target instance row.
(4) Click Queue Management, then click the New button.
(5) Clicking New and the following window will appear, select Yes for "Persistent or Not".
Set up Message Persistence
After the queue is set to persistent, you can set MessageProperties to PERSISTENT_TEXT_PLAIN to send persistent messages to the queue.
An example of Java client is:
import com.rabbitmq.client.MessageProperties;
channel.basicPublish("", "my_queue",MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());