c# - 应用程序异常关闭时删除RabbitMQ Queue

标签 c# .net rabbitmq amqp rabbitmq-exchange

我正在使用 .NET RabbitMQ Client 库。我想开发一个消息系统。 为此,我已经实现了 RabbitMQ 的所有必要方法。此外,我还开发了用于删除队列的 dispose()。我在 FormClosing 事件中调用此方法,因此当用户通过单击关闭按钮关闭应用程序时将触发此方法,逻辑队列将被删除。到目前为止,所有代码都运行良好。

但是我的问题是

I'm not able to delete a queue at the time of closing the application without clicking on close button (let's just say closing application from task manager or from command prompt using taskkill command or any abnormally reasons) as this dispose() will not be triggered. At this time, queue will not be deleted until I delete it from management portal manually.

所以我的问题是,

How can I know that the application is closed and that orphan queue can be deleted?

最佳答案

RabbitMQ 公开了一个基于 REST 的管理 API,使您能够处理队列创建/删除。

你可以做的是让你的应用程序在启动时查询管理 API 以查看是否有任何队列因为之前的意外关闭而被遗弃,或者你可以有一个完全不同的服务来负责这样做(这是一个设计选择).

您可以通过 EasyNetQ Management API 查询您的管理 API :

managementClient.DeleteQueue(queue);

您可以找到完整的文档 here .

编辑:

阅读一些内容后,也许排他或自动删除队列就足够了?

Exclusive (used by only one connection and the queue will be deleted when that connection closes)

Auto-delete (queue is deleted when last consumer unsubscribes)

关于c# - 应用程序异常关闭时删除RabbitMQ Queue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997358/

相关文章:

c# - 对通用列表进行排序

c# - 从 MySQL 数据库中读取 BLOB 图像

nginx - Kubernetes nginx ingress rabbitmq 管理和 kibana

python - 如何使用 Pika 发送和接收 RabbitMQ 消息?

c# - CaSTLe Windsor 升级导致泛型类型出现 TypeLoadException

c# - 为什么 Custom DataAnnotationsModelMetadataProvider 的 CreateMetadata 永远不会被调用?

c# - 知道是否为 "All users"安装了应用程序

c# - 逆变值类型

c# - 对象类型具有 ToString()、GetHashCode()、GetType 等方法的原因是什么

java - 延迟处理死信队列