简体   繁体   English

将消息发送到完整的JMS队列

[英]Sending a message to a full JMS queue

I am writing a Java code that sends messages to a JMS queue. 我正在编写一个将消息发送到JMS队列的Java代码。 I am doing this by using "QueueSender.send()". 我是通过使用“QueueSender.send()”来做到这一点的。

The JMS queue itsels is sonicMQ but that's beside the point. JMS队列itsels是sonicMQ,但这不是重点。

My problem is that sometimes the JMS queue is full and the thread that tries to send messages to the queue is starved. 我的问题是,有时JMS队列已满,尝试向队列发送消息的线程会被饿死。

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. 顺便说一句,JMS队列代码本身是我无法企及的。 I can only change only the client code. 我只能更改客户端代码。

Thank you. 谢谢。

You can send the messages asynchronic to do so setAsynchronousDeliveryMode with Constants.ASYNC_DELIVERY_MODE_ENABLED in the ConnectionFactory 您可以发送消息asynchronic以在ConnectionFactory中使用Constants.ASYNC_DELIVERY_MODE_ENABLED执行setAsynchronousDeliveryMode

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 progress.message.jclient类ConnectionFactory中查看更多详细信息

The JMS queue itself is sonicMQ but that's beside the point. JMS队列本身就是sonicMQ,但这不是重点。

Not really, this QueueMaxSize property is SonicMQ specific if I'm not wrong. 不是真的,如果我QueueMaxSize ,这个QueueMaxSize属性是SonicMQ特有的。

My problem is that sometimes the JMS queue is full and the thread that tries to send messages to the queue is starved. 我的问题是,有时JMS队列已满,尝试向队列发送消息的线程会被饿死。

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: 我对关于QueueMaxSize属性的Progress Sonic MQ性能调优指南7.5QueueMaxSize是,这是正常(和想要的)行为:

The total size of messages stored for a queue is the QueueMaxSize . 为队列存储的消息总大小为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). 现在, 可能可以通过JMX客户端获取通知,但我不确定这在您的上下文中是否可行(如果您想进一步挖掘或联系,请查看Progress SonicMQ管理编程指南V7.5)支撑)。 But I'm really not sure this would work. 但我真的不确定这会起作用。 Actually, I don't know if what you want to do is a good idea. 实际上,我不知道你想做什么是个好主意。

The behavoir you describe is SonicMQ specific, it is called Flow Control. 您描述的行为是SonicMQ特有的,它被称为流量控制。 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. 我可以想象处理此行为的唯一方案是使用Managemnt API或JMX客户端。 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. 当FlowControl发生时,SonicMQ可以生成通知,这里可以监听这些事件。

However: this is only possible with the proprietary SonicMQ API, you can not do this with Standard JMS. 但是:这只能通过专有的SonicMQ API实现,您无法使用标准JMS执行此操作。 I would ask the administrators of the SonicMQ environment to watch the FLow Control events and react appropriately... 我会要求SonicMQ环境的管理员观看FLOW Control事件并做出适当反应......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM