学习rabbitQM --Publish/Subscribe
the producer can only send messages to an exchange
An exchange is a very simple thing. On one side it receives messages from producers and the other side it pushes them to queues
There are a few exchange types available: direct, topic, headers and fanout.
The fanout exchange is very simple. As you can probably guess from the name, it just broadcasts all the messages it receives to all the queues it knows. And that's exactly what we need for our logger.
pulish:
var message = GetMessage(args);
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "logs",
routingKey: "",
basicProperties: null,
body: body);
received:
var queueName = channel.QueueDeclare().QueueName;
channel.QueueBind(queue: queueName,
exchange: "logs",
routingKey: "");
参考文档: https://www.rabbitmq.com/tutorials/tutorial-three-dotnet.html