RabbitMQ与.net core(三) fanout类型Exchange 与 消息的过期时间 与 队列的存活时间

fanout类型的Exchange的特点是会把消息发送给与之绑定的所有Queue中,我们来测试一下。代码如下

using RabbitMQ.Client; using System; using System.Text; using System.Threading; using System.Threading.Tasks; namespace RabbitMQConsole { class Program { static void Main(string[] args) { ConnectionFactory factory = new ConnectionFactory(); factory.HostName = "39.**.**.**"; factory.Port = 5672; factory.VirtualHost = "/"; factory.UserName = "root"; factory.Password = "root"; var exchange = "change3"; var route = "route2"; var queue3 = "queue3"; var queue4 = "queue4"; var queue5 = "queue5"; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange, type: "fanout", durable: true, autoDelete: false); channel.QueueDeclare(queue3, durable: true, exclusive: false, autoDelete: false); channel.QueueBind(queue3, exchange, queue3); channel.QueueDeclare(queue4, durable: true, exclusive: false, autoDelete: false); channel.QueueBind(queue4, exchange, queue4); channel.QueueDeclare(queue5, durable: true, exclusive: false, autoDelete: false); channel.QueueBind(queue5, exchange, queue5); var props = channel.CreateBasicProperties(); props.Persistent = true; channel.BasicPublish(exchange, route, true, props, Encoding.UTF8.GetBytes("hello rabbit")); } } } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpgdzd.html