RabbitMQ的消息队列的持久化是一个很不错的功能,设置也非常简单。如下代码:

1、设置队列持久化(在声明队列的时候设置)

channel.QueueDeclare(queue: "q.log.error",//队列名称
                     durable: true,//当前队列是否持久化 true:是 false:不是
                     exclusive: false,
                     autoDelete: false,
                     arguments: null);

2、设置消息持久化(发布消息的时候设置)

 var body = Encoding.UTF8.GetBytes("测试消息");
 var properties = channel.CreateBasicProperties();
 //设置消息持久化
 properties.SetPersistent(true);                
 channel.BasicPublish(exchange: "e.log",
                      routingKey: "log.error",
                      basicProperties: properties,
                      body: body);

 

 posted on 2017-12-25 14:48  F风  阅读(338)  评论(0编辑  收藏  举报