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 消息队列是否存在?
基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
