简体   繁体   English

RabbitMQ RPC 如何自动删除回调队列

[英]RabbitMQ RPC How to automatically delete the callback queue

I would like to know how to delete the callback queue after the client receive the callback message.我想知道客户端收到回调消息后如何删除回调队列 After multiples RPC calls I have a lot of callback queues I'm not using any more.在多次 RPC 调用之后,我有很多不再使用的回调队列。

I declare the callback queue as following:我声明回调队列如下:

replyToQueueName = _channelListener.QueueDeclare(durable: false,
exclusive: false, autoDelete: true, arguments: null).QueueName;

I thought they were going to be deleted after use but this is not the case.我以为它们会在使用后被删除,但事实并非如此。 I can see with the management plugin the queues still have a consumer.我可以通过管理插件看到队列仍然有消费者。

Maybe I just must delete the queue after receive the callback message, but I'm not sure is the best approach: channel.QueueDelete("queue-name", false, false);也许我必须在收到回调消息后删除队列,但我不确定最好的方法是: channel.QueueDelete("queue-name", false, false);

I've been using this tutorial我一直在使用这个教程

I have found a solution (not sure if is the best solution).我找到了一个解决方案(不确定是否是最好的解决方案)。 After receive the callback message, I unsubscribe the consumer:收到回调消息后,我取消订阅消费者:

channel.BasicCancel(consumer.ConsumerTags[0]);

This way the callback queue has no consumer, and it's deleted immediately.这样回调队列就没有消费者了,它会立即被删除。

Cancelling a Consumer (Unsubscribing)取消消费者(退订)

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

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