使 EJB MessageDrivenBean 像 Def​​aultMessageListenerContainer(JMS、OpenMQ)一样工作

发布于 2024-12-19 01:13:54 字数 778 浏览 3 评论 0原文

我使用 Spring DefaultMessageListenerContainer 在设置 MessageSelector 值时获得一些动态优势,因为我使用的是 Glassfish OpenMQ,它在这方面并不是那么先进。 让我们看一下 JMS 消息。侦听器发出特定故障,这意味着:x 秒后重试。它再次尝试失败:在 x*y 秒后重试,依此类推,时间呈指数增长。如果重试 z 后仍无法处理它,请将其视为有害 JMS 消息。

DefaultMessageListenerContainer dmlc;
dmlc.stop();
dmlc.setMessageSelector(String.format("retries < %d AND retryTime <= %d", z, System.currentTimeMillis()));
dmlc.start();

我对这个解决方案不太满意,特别是当 Spring 文档在这里提出警告时:-)。不过,目前来说,一切都满足我们的需求。

现在,我在不同的应用程序上有多个 EJB 消息使用者。其中一些需要messageSelector的这种动态变化。不幸的是,据我所知,EJB MDB 不支持这种动态“功能”。例如,请参阅此

这是正确的吗? EJB 解决方案有解决方法吗?我将不胜感激任何帮助。

I am using the Spring DefaultMessageListenerContainer to gain some dynamic benefits in setting the MessageSelector value since I am using the Glassfish OpenMQ which is not that advanced in that regards.
Let's have a JMS message. The listener issues a specific failure that means: retry after x seconds. It tries again with failure: retry after x*y seconds, and so on the time grows exponentially. If you cannot handle it after z retries, consider it as a poison JMS message.

DefaultMessageListenerContainer dmlc;
dmlc.stop();
dmlc.setMessageSelector(String.format("retries < %d AND retryTime <= %d", z, System.currentTimeMillis()));
dmlc.start();

I am not that satisfied with this solution, especially, when the Spring docs raise warning here:-). However, for the moment things meet our needs.

Now, I have a number of EJBs message consumers on different applications. Some of them need such dynamic changes of the messageSelector. Unfortunately, and to-my-best-knowledge, EJB MDBs do not support such dynamic "features". For example, see this.

Is that correct? is there a workaround for an EJB solution? I would appreciate any help.

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

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

发布评论

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

评论(1

最佳男配角 2024-12-26 01:13:54

要实现消息选择器的动态更改,您需要直接在 JMS 中实现它,例如

ConnectionFactory cf;
Connection connection = cf.createConnection();
session = connection.createSession(transactional, acknowledgeMode);

MessageConsumer messageConsumer = session.createConsumer(destination, "message selector");

此外,您需要将此代码放置在它自己执行的某个位置,也许在异步任务中?但你会重新发明轮子,因为 Spring DMLC 做得更好。

我不知道你为什么要这样做:

  • 为了负载平衡?消息代理应该处理这个问题。
  • 用于处理临时停机?队列应配置为能够存储适当数量的消息,或将传递切换到集群中的其他节点。

To achieve dynamic changes to the message selector, you'd need to implement it straight in JMS, e.g.

ConnectionFactory cf;
Connection connection = cf.createConnection();
session = connection.createSession(transactional, acknowledgeMode);

MessageConsumer messageConsumer = session.createConsumer(destination, "message selector");

Additionally, you'd need to place this code some place it executes on its own, perhaps in an asynchronous task? But you'd be reinventing the wheel, as Spring DMLC does that better.

I don't know why you're doing this:

  • for load balancing? The message broker should take care of this.
  • for handling temporary downtimes? The queue should be configured to be able to store appropriate number of messages, or switch delivery to other node in cluster.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文