向已满的 JMS 队列发送消息

发布于 2024-08-19 20:40:39 字数 263 浏览 6 评论 0原文

我正在编写一个将消息发送到 JMS 队列的 Java 代码。 我通过使用“QueueSender.send()”来做到这一点。

JMS 队列本身是 sonicMQ,但这不是重点。

我的问题是,有时 JMS 队列已满,并且尝试向队列发送消息的线程处于饥饿状态。

有没有办法让我在发送消息之前知道队列是否已满?在这种情况下,我更愿意在日志中打印异常。

顺便说一句,JMS 队列代码本身超出了我的能力范围。我只能更改客户端代码。

谢谢。

I am writing a Java code that sends messages to a JMS queue.
I am doing this by using "QueueSender.send()".

The JMS queue itsels is sonicMQ but that's beside the point.

My problem is that sometimes the JMS queue is full and the thread that tries to send messages to the queue is starved.

Is there a way for me to know if the queue is full before sending the message? In this case I would prefer to print an exception to the log.

By the way, the JMS queue code itself is out of my reach. I can only change only the client code.

Thank you.

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

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

发布评论

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

评论(3

ペ泪落弦音 2024-08-26 20:40:39

在 ConnectionFactory 中使用 Constants.ASYNC_DELIVERY_MODE_ENABLED 异步发送消息,

您可以使用 spring

<bean id="connectionFactory" class="progress.message.jclient.QueueConnectionFactory">
...
 <property name="asynchronousDeliveryMode">
  <util:constant static-field=  "progress.message.jclient.Constants.ASYNC_DELIVERY_MODE_ENABLED"/>
</property>
</bean>

请参阅更多详细信息
progress.message.jclient 类 ConnectionFactory

You can send the messages asynchronic to do so setAsynchronousDeliveryMode with Constants.ASYNC_DELIVERY_MODE_ENABLED in the ConnectionFactory

using spring

<bean id="connectionFactory" class="progress.message.jclient.QueueConnectionFactory">
...
 <property name="asynchronousDeliveryMode">
  <util:constant static-field=  "progress.message.jclient.Constants.ASYNC_DELIVERY_MODE_ENABLED"/>
</property>
</bean>

see more details in
progress.message.jclient Class ConnectionFactory

优雅的叶子 2024-08-26 20:40:39

JMS 队列本身是 sonicMQ,但这不是重点。

事实并非如此,如果我没记错的话,这个 QueueMaxSize 属性是 SonicMQ 特定的。

我的问题是,有时 JMS 队列已满,并且尝试向队列发送消息的线程处于饥饿状态。

我对 Progress Sonic MQ 性能调整指南 7.5 关于 < code>QueueMaxSize 属性是这是正常的(也是想要的)行为:

为队列存储的消息的总大小是QueueMaxSize。当队列发送者
尝试将消息传递到最大大小的队列,发送者将被流
受控制,消息的发送将被阻止,直到有可用空间为止。

现在,也许可以通过 JMX 客户端获取通知,但我不确定这在您的上下文中是否可行(请查看 Progress SonicMQ 管理编程指南 V7.5 如果您想进一步深入了解或联系支持人员)。但我真的不确定这是否有效。事实上,我不知道你想做的是否是一个好主意。

The JMS queue itself is sonicMQ but that's beside the point.

Not really, this QueueMaxSize property is SonicMQ specific if I'm not wrong.

My problem is that sometimes the JMS queue is full and the thread that tries to send messages to the queue is starved.

My understanding of the Progress Sonic MQ Performance Tuning Guide 7.5 about the QueueMaxSize Property is that this is the normal (and wanted) behavior:

The total size of messages stored for a queue is the QueueMaxSize. When a Queue Sender
tries to deliver a message to a queue that is at its maximum size, the sender will be flow
controlled and the send of the message will be blocked until space is available.

Now, it would be maybe possible to get a Notification with a JMX client but I'm not sure this is feasible in your context (have a look at the Progress SonicMQ Administrative Programming Guide V7.5 if you want to dig this further or contact the support). But I'm really not sure this would work. Actually, I don't know if what you want to do is a good idea.

离鸿 2024-08-26 20:40:39

您描述的行为是 SonicMQ 特定的,称为流量控制。在某些情况下,这是一个非常好的功能,但在其他情况下,这可能会导致整排系统出现问题。不幸的是,我还没有找到任何方法来改变基于队列的场景中的这种行为。

我可以想象处理此行为的唯一场景是使用 Managemnt API 或 JMX 客户端。一般有两种可能性:

  • 在发送消息之前检查队列的最大和实际大小
  • 当 FlowControl 发生时 SonicMQ 可以生成通知,这里可以监听这些事件。

但是:这只能通过专有的 SonicMQ API 实现,而无法通过标准 JMS 实现这一点。我会要求 SonicMQ 环境的管理员观察流量控制事件并做出适当的反应...

The behavoir you describe is SonicMQ specific, it is called Flow Control. In some scenarios this is a pretty good feature, in others this may cause a whole row of systems becoming problems. Unfortunately i haven' found any method to change this behaviour in queue based scenarios.

The only scenarios that i can imagine to handle this behavior is to use the Managemnt API or a JMX client. There are two general possibilities:

  • Check the maximum and actual size of the queue before sending the message
  • when FlowControl occurs SonicMQ can generate a notification, here it is possible to listen to these events.

However: this is only possible with the proprietary SonicMQ API, you can not do this with Standard JMS. I would ask the administrators of the SonicMQ environment to watch the FLow Control events and react appropriately...

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