简体   繁体   English

纠正在RabbitMQ中导致交换失败的内容

[英]Correct what to catch exchange down in RabbitMQ

As per the tutorial, I use var consumer = new EventingBasicConsumer(channel); 按照教程,我使用var consumer = new EventingBasicConsumer(channel); to register message on the queue. 在队列上注册消息。

But I noticed that if the exchange is deleted, (forcefully using the API), or by stopping rabbit, I don't actually get any notification that something is wrong 但是我注意到,如果删除了交换((强制使用API​​)或通过停止Rabbit),实际上我没有收到任何错误消息

var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
    var body = ea.Body;
    var message = Encoding.UTF8.GetString(body);
    Console.WriteLine(" [x] Received {0}", message);
};

What events can I register to tell if/when the exchange was deleted or if I was somehow disconnected for whatever reason? 我可以注册哪些事件来告知是否/何时删除了交换,或者由于某种原因我是否以某种方式断开了连接?

There is nothing wrong if an exchange is deleted. 如果删除了交换,则没有任何错误。 Since your consumer consumes from a queue , the only result is that no more messages are routed from this exchange to the queue. 由于您的使用者是从队列中消费的,因此唯一的结果是不再有消息从此交换路由到队列。

This is different from your consumer being disconnected from the queue or the queue being deleted which will result in your consumer being disconnected. 这与您的使用者从队列断开连接或删除队列不同,这将导致您的使用者断开连接。 Check out HandleModelShutdown and other methods your consumer can implement for such cases. 查看HandleModelShutdown以及消费者可以为此类情况实现的其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM