开发者

Sending a message to a full JMS queue

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.


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


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜