如何暂停 JMS 主题订阅者接收消息
我的设置:在 JBoss 4.2.3 上运行 JBoss Messaging 1.4
我有几个订阅一个主题的 MDB,并且 MDB 的 onMessage() 尝试将收到的消息分别传递到一个 Web 服务。
我的问题是,当网络服务离线时,我不知道如何暂停订阅。
我的计划是在 onMessage() 中执行以下操作:
- 请尝试传递到 Web 服务
- 如果离线,
- : --> 暂停订阅
- --> 在 onMessage() 中抛出异常以使 JMS 重新传递消息 直到Web服务再次上线
- --> 启动订阅
我只想暂停有问题的订阅 - 而不是我的所有订阅者。
关于如何解决这个问题有什么建议吗?
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():
- try to deliver to web service
- if offline:
- --> pause the subscription
- --> throw exception in onMessage() to make JMS redeliver the message
until the web service goes online again - --> 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能阻止监听主题中任何传入消息的监听者吗?
这是 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.
这与如何暂时禁用消息中的场景非常相似 唯一的区别是
您是 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.
为什么要暂停订阅? 只需抛出异常并进入睡眠状态,例如 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.