如何限制侦听 Jboss JMS 队列的 MDB 实例数量
我在以下设置中遇到问题:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试额外的激活配置属性:
其中 someNumber 是您想要的最大实例数。
Try an additional acitivation config property:
where someNumber is the maximum number of instances you want.
如果 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).