rabbitmq小记

发布时间 2023-11-20 15:17:08作者: 81

发topic代码,创建交换器,数据直接按routingKey发送到交换器中:    

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    // 创建交换器
                    channel.ExchangeDeclare("logs3", ExchangeType.Topic);

                    // 发送消息
                    channel.BasicPublish(exchange: "logs3", routingKey: "red.green", basicProperties: null, body: Encoding.UTF8.GetBytes($"测试red.green"));
                    channel.BasicPublish(exchange: "logs3", routingKey: "red.yellow.green", basicProperties: null, body: Encoding.UTF8.GetBytes($"测试red.yellow.green"));
                }
            }