互斥量是rabbitmq

发布于 2024-12-26 10:41:33 字数 265 浏览 2 评论 0原文

RabbitMQ 队列中是否可以有互斥体,即如果客户端正在从队列中读取,则其他客户端不应从队列中读取。这可能吗?

让我解释一下我的场景:

两个应用程序在两个不同的服务器上运行。读取同一个队列。但是,如果一个应用程序正在运行并从队列中读取消息,则另一个应用程序不应执行任何操作。如果主应用程序失败或停止,则其他应用程序应该 开始从此队列中读取。

这是一种故障转移机制。以前有人尝试过这个吗?非常感谢任何帮助。

Is that possible to have mutex in RabbitMQ queue, i.e. If a client is reading from the queue, no other client should read from the queue. is that possible?

Let me explain my scenario:

Two application running in two different servers. reading the same queue. But, if one application is running and reading the messages from the Queue, the other application should not do anything. if the Main application fails or stopped, then the other application should
start reading from this queue.

This is kind of a fail over mechanism. Have anyone tried this before. Any help is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静水深流 2025-01-02 10:41:33

只要我搜索过,就找不到解决方案......一个简单的解决方案是

  • 创建一个队列,将其称为“锁定队列”。

  • 只有一条消息使应用程序从队列中读取它。

  • 当应用程序在另一台服务器中启动时,它将等待队列中的消息。所以,如果第一个失败了,那么第二个失败了

  • 将读取消息并开始处理它应该从中读取的所需队列中的消息。

队列中的互斥体,就是这样。
注意:只有当锁定队列中只有消息时,此方法才有效。确保在您的应用程序中处理它。

As long as i have searched, no solutions found...A simple solution is

  • create a queue call it as Lock Queue.

  • Have only one message make the application to read it from the queue.

  • When ever the application starts in a another server, it will wait for the message in the Queue. so, if the first one fails second

  • one will read the message and start processing the message in desired queue from which it should read.

A Mutex in Queue, that's it.
Note: This approach will work only if there is only message in the lock queue. make sure you handle it in your application.

清音悠歌 2025-01-02 10:41:33

此演讲明确解释了为什么这是一个坏主意:

http:// www.youtube.com/watch?v=XiXZOF6dZuE&feature=share&t=29m55s

从 ~ 29m 55秒内

This talk explicitly explains why this is a bad idea:

http://www.youtube.com/watch?v=XiXZOF6dZuE&feature=share&t=29m55s

from ~ 29m 55s in

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文