AMQP协议:是一个金融级的消息队列,确保消息万无一失
1、消息发布端的确认
手动确认消息是否已经发送
场景:发布消息到RabbitMQ中,我们需要知道这个消息是否发布成功了。
*发布确认影响性能 confirm机制对性能的影响 《 tx机制对性能的影响
1)、confirm机制
1 channel.ConfirmSelect(); 2 channel.BasicPublish("headersExchange", string.Empty, properties, Encoding.UTF8.GetBytes("来自.net的问候")); 3 var isAllPublished = channel.WaitForConfirms();
2)、tx机制
1 try 2 { 3 //发布消息 4 //String exchange, 交换机名称 5 //String routingKey, routingKey 6 //IBasicProperties basicProperties, 发布属性 7 //Byte[] body 消息内容 8 channel.TxSelect(); 9 channel.BasicPublish("headersExchange", string.Empty, properties, Encoding.UTF8.GetBytes("来自.net的问候")); 10 channel.TxCommit(); 11 } 12 catch (Exception) 13 { 14 channel.TxRollback(); 15 }
2、消息消费端的确认
原文:https://www.cnblogs.com/fanqisoft/p/10392506.html