交换器持久化:
//
// 摘要:
// Declare an exchange.
//
// 备注:
// The exchange is declared non-passive and non-internal. The "nowait" option is
// not exercised.
[AmqpMethodDoNotImplement(null)]
void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, IDictionary<string, object> arguments);
bool durable, bool autoDelete, IDictionary<string, object> arguments);
队列持久化:
//
// 摘要:
// Declare a queue.
[AmqpMethodDoNotImplement(null)]
QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments);
bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments);
消息持久化:
var properties = channel.CreateBasicProperties();
properties.Persistent = true;
channel.BasicPublish(EXCHANGE_NAME, ROUTING_KEY,true, properties, body);
注意:
1.交换器没有持久化,RabbitMQ重启后,消息不回丢失,但是交换器丢失,不能再发送消息到这个交换器了。
2.设置了队列和消息持久化之后,当rabbitMQ重启服务,消息依旧存在;单独设置队列持久化,重启后消息会丢失;单独设置消息持久化,重启之后队列会消失,继而消息也会丢失。
3.交换器、队列、消息都持久化也并不一定完全保证消息不回丢失。
更多精彩请关注公众号:隔壁王小猿(gbwxy-happy)