RabbitMQ之消息持久化
原文地址 消息的可靠性是RabbitMQ的一大特色,那么RabbitMQ是如何保证消息可靠性的呢――消息持久化。 为了保证RabbitMQ在退出或者crash等异常情况下数据没有丢失,需要将queue,exchange和Message都持久化。 queue的持久化 queue的持久化是通过durable=true来实现的。 一般程序中这么使用: Connection connection = connectionFactory . newConnection (); Channel channel = connection . createChannel (); channel . queueDeclare ( "queue.persistent.name" , true , false , false , null ); 关键的是第二个参数设置为true,即durable=true. Channel类中queueDeclare的完整定义如下: /** * Declare a queue * @see com.rabbitmq.client.AMQP.Queue.Declare * @see com.rabbitmq.client.AMQP.Queue.DeclareOk * @param queue the name of the queue * @param durable