JMS Timeout or TimeToLive

会有一股神秘感。 提交于 2019-12-06 05:09:24

You have to make use of some implementation specific functionality to fulfill your requirements. The JMS specification does neither define which action is taken with a timed out message, nor does it offer you any reasonable criteria selection when polling messages from a queue.

Most (if not all) JMS implementations do however offer the concept of DLQs (dead letter queues). If a message cannot be delivered to a regular consumer or times out, the JMS implementation will most likely be able to move the message to a DLQ, which is basically also a regular queue with its own listener.

So, if you set up two queues, Q1 and Q2 and configure Q2 as a DLQ for Q1, you would do your normal request processing in a listener on Q1 and implement an additional listener for Q2 to do the error/timeout handling.

Synchronous interaction over JMS might be of help to you either. Basicly on the client side you:

  1. send a message with a correlation id and time-to-live
  2. receive a message (usually in the same thread) using the same correlation id and specifying timeout (time-to-live == timeout so if you treat it dead, it's really dead)

On the other side, server:

  1. on an incoming message must fetch the correlation id
  2. specify that correlation id for a response while sending it back to the client. Of course server must be quick enough to fit the timeout/time-to-live threshold.

So on the client side you are always sure what's happend to the message that was sent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!