获取将消息发送到队列/交换的生产者的IP

时间:2018-11-02 03:51:50

标签: rabbitmq

出于故障排除的目的,我想获取将消息发送到特定队列或交换的生产者列表。我没有在rabbitmq控制台中看到任何选项来获取上述详细信息。一些生产者正在堆积一个特殊的队列,我试图找出生产者在队列中堆积消息的IP。

有人可以指导我吗?

1 个答案:

答案 0 :(得分:1)

默认情况下您没有此信息,但是您可以使用消息头来执行此操作。

例如:

string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);

var properties = new BasicProperties();
properties.Headers = new Dictionary<string, object>();
properties.Headers.Add("senderip", InetAddress.getLocalHost().getHostAddress());
properties.Headers.Add("custominfo", "info" );

channel.BasicPublish(exchange: "", routingKey: "mykey", basicProperties: properties,body: body);

收到消息后,您可以解码标题