• rabbitmq topic


                var factory = new ConnectionFactory();
                factory.HostName = "localhost";
                factory.UserName = "admin";
                factory.Password = "admin";
    
                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare("topic_dev", "topic", true, false, null);
                        channel.QueueDeclare("login", true, false, false, null);
                        channel.QueueDeclare("signin", true, false, false, null);
                        channel.QueueBind("login", "topic_dev", "#.login.#", null);
                        channel.QueueBind("signin", "topic_dev", "#.signin.#", null);
    
                        var properties = channel.CreateBasicProperties();
                        properties.DeliveryMode = 2;
    
                        var consumer = new EventingBasicConsumer(channel);
                        consumer.Received += (model, ea) =>
                        {
                            var body = ea.Body.ToArray();
                            var msg = Encoding.UTF8.GetString(body);
                            Console.WriteLine($"login => {msg}, DeliveryTag={ea.DeliveryTag}, Redelivered={ea.Redelivered}, RoutingKey={ea.RoutingKey}");
                            channel.BasicAck(ea.DeliveryTag, false);
                        };
                        channel.BasicConsume("login", false, consumer);
    
                        var consumer1 = new EventingBasicConsumer(channel);
                        consumer1.Received += (model, ea) =>
                        {
                            var body = ea.Body.ToArray();
                            var msg = Encoding.UTF8.GetString(body);
                            Console.WriteLine($"signin => {msg}, DeliveryTag={ea.DeliveryTag}, Redelivered={ea.Redelivered}, RoutingKey={ea.RoutingKey}");
                            channel.BasicAck(ea.DeliveryTag, false);
                        };
                        channel.BasicConsume("signin", false, consumer1);
    
                        string message = "I am jonney";
                        channel.BasicPublish("topic_dev", "login.signin", properties, Encoding.UTF8.GetBytes(message)); 
                        Console.WriteLine($"Send:{message}");
    
                        Console.ReadLine();
                    }
                }
  • 相关阅读:
    学习使用GitHub托管团队代码开展协作
    实验一 GIT 代码版本管理
    实验五 单元测试
    实验二 结对编程(阶段二)
    结对编程 第一阶段
    实验一 GIT代码版本管理
    实验五 单元测试
    实验二 结对编程(第二阶段)
    结对编程 第一阶段报告
    实验一 GIT代码版本管理
  • 原文地址:https://www.cnblogs.com/jonney-wang/p/13511922.html
Copyright © 2020-2023  润新知