如何暂停 JMS 主题订阅者接收消息

发布于 2024-08-01 17:31:45 字数 419 浏览 5 评论 0原文

我的设置:在 JBoss 4.2.3 上运行 JBoss Messaging 1.4

我有几个订阅一个主题的 MDB,并且 MDB 的 onMessage() 尝试将收到的消息分别传递到一个 Web 服务。

我的问题是,当网络服务离线时,我不知道如何暂停订阅。

我的计划是在 onMessage() 中执行以下操作:

  1. 请尝试传递到 Web 服务
  2. 如果离线,
  3. : --> 暂停订阅
  4. --> 在 onMessage() 中抛出异常以使 JMS 重新传递消息 直到Web服务再次上线
  5. --> 启动订阅

我只想暂停有问题的订阅 - 而不是我的所有订阅者。

关于如何解决这个问题有什么建议吗?

My setup: JBoss Messaging 1.4 running on JBoss 4.2.3

I have a couple of MDB's that subscribes on one topic, and the MDB's onMessage() tries to deliver the received message to one web service each.

My problem is that I can't figure out how to pause the subscriptions in the case when the web service is offline.

My plan is to do the following in onMessage():

  1. try to deliver to web service
  2. if offline:
  3. --> pause the subscription
  4. --> throw exception in onMessage() to make JMS redeliver the message
    until the web service goes online again
  5. --> start the subscription

I want to pause ONLY the one subscription that have the problem - NOT all my subscribers.

Any suggestion on how to solve this?

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

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

发布评论

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

评论(3

只为守护你 2024-08-08 17:31:45

你不能阻止监听主题中任何传入消息的监听者吗?

这是 Listener 文档的链接,它有一个暂停方法。 您可以遵循相同的方法,详细信息可以在它们的分布中找到。
http://synapse.apache.org/apidocs/ org/apache/synapse/transport/jms/JMSListener.html

另一篇向您展示如何停止消费者:
http:// livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/services/messaging/adapters/JMSConsumer.html#stop()

它们基本上都是相同的。

Can't you stop the listener who listens to any incoming messages in the topic?

Here is the link for the doc of Listener, and it has a pause method. You can follow the same approach, and detail can be found in their distribution.
http://synapse.apache.org/apidocs/org/apache/synapse/transport/jms/JMSListener.html

Another one to show you how to stop your consumer:
http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/services/messaging/adapters/JMSConsumer.html#stop()

They are all basically the same.

ㄟ。诗瑗 2024-08-08 17:31:45

这与如何暂时禁用消息中的场景非常相似 唯一的区别是

您是 MDB 而不是普通的 Java 客户端。 您是否可以避免从 onMessage() 返回,直到您的 Web 服务再次工作? 您必须安排您的 onMessage() 逻辑来阻止或睡眠。 睡眠在技术上违反了 EJB 规范,但根据您考虑的替代方案,它可能并不更丑陋。

This is very similar to the scenario in How to temporarily disable a message listener

Only difference is you're an MDB rather than a plain Java client. Could you just avoid returning from onMessage() until your web service is working again? You'd have to arrange your onMessage() logic to block or sleep. Sleeping is a technical violation of the EJB spec, but depending on what you're considering as an alternative, it may be no uglier.

傾城如夢未必闌珊 2024-08-08 17:31:45

为什么要暂停订阅? 只需抛出异常并进入睡眠状态,例如 30 秒。 异常将回滚 JMS 事务并将消息放回到队列中。

睡眠可确保在 Web 服务离线时这不会成为 DoS 攻击(通过每秒多次传送和回滚消息)。

[编辑] 如果您对同一主题有许多侦听器(出于性能原因),我建议创建一个独立的进程来侦听“Web 服务关闭”消息,并在这种情况下取​​消订阅所有正常侦听器。

然后,该进程应该等到服务再次可用并重新订阅侦听器。

Why do you want to pause the subscription? Just throw an exception and go to sleep for, say, 30 seconds. The exception will roll back the JMS transaction and put the message back into the queue.

The sleep makes sure that this doesn't become a DoS attack while the web service is offline (by delivering and rolling back the message many times per second).

[EDIT] If you have many listeners for the same topic (for performance reasons), I suggest to create an independent process which listens for "Web service down" messages and unsubscribes all the normal listeners in this case.

The process should then wait until the service is available again and re-subscribe the listeners.

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