How can I check whether a RabbitMQ message queue exists or not?(如何检查 RabbitMQ 消息队列是否存在?)
问题描述
如何检查消息队列是否已经存在?
How can I check whether a message Queue already exists or not?
我有 2 个不同的应用程序,一个创建队列,另一个从该队列读取.
I have 2 different applications, one creating a queue and the other reading from that queue.
所以如果我运行首先从队列中读取的客户端,它就会崩溃.
所以为了避免这种情况,我想先检查队列是否存在.
So if I run the Client which reads from the queue first, than it crashes.
So to avoid that i would like to check first whether the queue exists or not.
这是我如何读取队列的代码片段:
here is the code snippet of how I read the queue:
QueueingBasicConsumer <ConsumerName> = new QueueingBasicConsumer(<ChannelName>);
<ChannelName>.BasicConsume("<queuename>", null, <ConsumerName>);
BasicDeliverEventArgs e = (BasicDeliverEventArgs)<ConsumerName>.Queue.Dequeue();
推荐答案
不用检查了.
queue.declare 是幂等操作.所以,如果你运行一次,两次,N次,结果还是一样的.
queue.declare is an idempotent operation. So, if you run it once, twice, N times, the result will still be the same.
如果要确保队列存在,只需在使用前声明即可.确保每次都以相同的持久性、排他性、自动删除性声明它,否则你会得到一个例外.
If you want to ensure that the queue exists, just declare it before using it. Make sure you declare it with the same durability, exclusivity, auto-deleted-ness every time, otherwise you'll get an exception.
如果您确实需要检查队列是否存在(通常不需要),请对队列进行被动声明.如果队列存在,则该操作成功,如果不存在,则操作失败.
If you actually do need to check if a queue exists (you shouldn't normally need to), do a passive declare of the queue. That operation succeeds if the queue exists, or fails in an error if it doesn't.
这篇关于如何检查 RabbitMQ 消息队列是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查 RabbitMQ 消息队列是否存在?
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01