如何限制侦听 Jboss JMS 队列的 MDB 实例数量

发布于 2024-10-16 19:05:53 字数 1062 浏览 4 评论 0原文

我在以下设置中遇到问题:

Java 应用程序将电子邮件消息发送到 JMS 队列,然后侦听队列的 MDB 使用 onMessage 方法获取电子邮件消息,它在 Gmail SMTP 上打开连接,发送电子邮件到 SMTP 并关闭连接。对 JMS 队列中的所有消息执行此操作。

当队列中同时有多达 5 条消息时,它的工作效果非常好。所有邮件均由 5 个不同的 MDB 实例同时获取,因此我有 5 个与 Gmail SMTP 服务器的并发连接。但是,当 JMS 队列中有更多消息时,我收到来自 Gmail SMTP 服务器的连接错误。前 5 条消息已正确发送,但其余消息未正确发送,因此其他消息会丢失,因为它们不再位于队列中。

所以我的问题是,是否可以限制侦听 JMS 队列的 MDB 实例的数量?如果我最多有 5 个 MDB,那么即使队列中有 1000 条消息,清空队列也会花费更长的时间,但至少我不会丢失任何消息。

任何其他解决此问题的建议将不胜感激。

这是Jboss版本:

[服务器]版本 ID:JBoss [Trinity] 4.2.3.GA(内部版本:SVNTag=JBoss_4_2_3_GA 日期=200807181417)

MDB 的配置如下:

@MessageDriven(activationConfig = {   
  @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue" ),   
  @ActivationConfigProperty( propertyName = "destination", propertyValue = "queue/emailQueue")  
})

您需要更多吗?

谢谢

编辑2011-02-14
也许我想要限制 MDB 实例的数量是错误的。我看到一个关于JMS线程数的配置。如果我限制发送到 MDB 的线程数量,也许可以解决我的问题? JMS 是否会等到 MDB 可用后再再次发布消息?这样做有副作用吗?你尽管请。 谢谢
结束编辑

I'm having a problem with the following setup:

A Java application send email msg to a JMS queue, then an MDB listening to the queue get the email msg with the onMessage method, it open a connection on the Gmail SMTP, send the email to the SMTP and close the connection. Doing this on all message in the JMS queue.

It is working great when I have up to 5 messages in the queue at the same time. All messages are picked-up in the same time by 5 different instances of the MDB, so I have 5 concurrent connection to the Gmail SMTP server. But when there is more messages in the JMS queue, I get a connection error from the Gmail SMTP server. The 5 first messages are sent correctly, but not the rest of the bunch, so the other messages are lost because they are not in the queue anymore.

So my question is, is it possible to limit the number of MDB instance that will listen to the JMS queue? If I have a maximum of 5 MDB, then even if I have 1000 messages in the queue, it will just take longer to empty the queue, but at least I wont lose any message.

Any other suggestion to resolve this issue would be very much appreciated.

Here is the Jboss version:

[Server] Release ID: JBoss [Trinity] 4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)

and the config of the MDB is as following :

@MessageDriven(activationConfig = {   
  @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue" ),   
  @ActivationConfigProperty( propertyName = "destination", propertyValue = "queue/emailQueue")  
})

Do you need more?

Thanks

EDIT 2011-02-14
Maybe I'm all wrong wanting to limit the number of MDB instance. I saw a config about the number of JMS threads. If I limit the number of thread that will post to the MDB, maybe it will resolve my issue? Will the JMS wait until a MDB is available before posting msg again? Is there any side effect to do that? Your though please.
Thanks
END EDIT

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

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

发布评论

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

评论(2

清音悠歌 2024-10-23 19:05:53

尝试额外的激活配置属性:

@ActivationConfigProperty( propertyName = "maxSession", propertyValue = "someNumber")

其中 someNumber 是您想要的最大实例数。

Try an additional acitivation config property:

@ActivationConfigProperty( propertyName = "maxSession", propertyValue = "someNumber")

where someNumber is the maximum number of instances you want.

缺⑴份安定 2024-10-23 19:05:53

如果 JBoss 4 具有限制无状态会话 bean 实例的选项,则一种选择是将消息处理代码移至此 bean,并将传入的 JMS 消息传递给它。 (IIRC bean 中的任何故障也会导致 JMS 消息未被确认,因此它会自动重试)。

If JBoss 4 has an option to limit the instances of a stateless session bean, one option could be to move the message processing code to this bean, and pass the incoming JMS messages to it. (IIRC any failures in the bean would also cause the JMS message to be unacknowledged so it would retry automatically).

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