RabbitMQ持久化+消息执行优先级

持久化
 
channel.QueueDeclare(queue:"hello",//队列名
durable:true,//持久化 
exclusive:false,//排他性,该队列仅对首次申明他的连接可见,并在连接断开时,自动删除
autoDelete:false,// 如果改队列没有任何订阅消息,该队列自动删除
arguments:null// 如果安装了队列优先级插件,可以设置优先级
)
 
channel.ExchangeDeclare(exchange:"MyExchange"........)
channel.QueueBind(“hello”,"MyExchange","",arguments:null)
通过 队列和Exchage 绑定 可以实现 队列持久化
 
IBasicProperties pp=channel.CreateBsicProperties();
pp.Persistent=true;
消息持久化
 
 
 
优先级
channel.QueueDeclare(queue:"hello",//队列名
durable:true,//持久化
exclusive:false,//排他性,该队列仅对首次申明他的连接可见,并在连接断开时,自动删除
autoDelete:false,// 如果改队列没有任何订阅消息,该队列自动删除
arguments:new Dictionary<string,object>{"x-max-priority",10} // 如果安装了队列优先级插件,可以设置优先级
)
IBasicProperties pp=channel.CreateBsicProperties();
pp.Persistent=true;
 
pp.Priority=2; 设置消息优先级别 ,值越高,越先被消费
 
 

posted @ 2022-04-10 10:59  周捷Jay  阅读(54)  评论(0编辑  收藏  举报