JMS超时或TimeToLive [英] JMS Timeout or TimeToLive

查看:274
本文介绍了JMS超时或TimeToLive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java EE和JMS的新手,我正在考虑使用JMS进行实现。

I am fairly new to Java EE and JMS and am looking at doing an implementation using JMS.

考虑以下情况:

情景

用户点击servlet。然后将消息从此servlet放入JMS服务器/队列。然后将响应发送回用户说消息排队。

A user hits a servlet. A message is then put into a JMS server/Queue from this servlet. A response is then sent back to the user saying "Message Queued".

选项1

使用者/ MDB从JMS队列接收消息并对其进行处理。这是正常的操作,非常标准。

The consumer/MDB receives the message from the JMS queue and processes it. This is normal operation and pretty standard.

选项2

没有消费者(出于任何原因)或接收者处理消息的速度太慢。所以我想要的是队列中的消息超时。一旦超时,就会发送电子邮件等(电子邮件就是一个例子)。

There is no consumer(for what ever reason) or the receiver is processing messages too slow. So what I would like is for the message in the queue to timeout. Once timed out, and email should be sent etc (email is just as an example).

阅读我在QueuSender类中找到的API规范/ Java EE 6教程

Reading the API spec/Java EE 6 tutorial I have found in the QueuSender class

void send(Message message, int deliveryMode, int priority, long timeToLive) 

因此,通过设置timeToLive,消息将从队列中逐出。问题是没有接口/回叫知道消息被驱逐。它只是消失了。或者我错了?

So by settings the timeToLive the message will be evicted from the queue. The problem is that the is no "interface/call back" to know that the message was evicted. It just disappears. Or am I mistaken?

我想到的另一种方法是让一个线程监视队列并逐出已过期的消息并将它们从队列中拉出来。但我不认为这是可能的,是吗?

Another approach I thought of was for a thread to monitor the queue and evict messages that are "expired" and pull them from the queue. But I don't think that is possible, is it?

任何关于这件事的光明都会受到重视。

Any light shed on this matter would greatly be appreciated.

推荐答案

您必须使用某些特定于实现的功能来满足您的要求。 JMS规范既没有定义对超时消息采取哪种操作,也没有在轮询来自队列的消息时为您提供任何合理的标准选择。

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.

大多数(如果然而,并非所有JMS实现都提供了DLQ(死信队列)的概念。如果消息无法传递给常规消费者或超时,则JMS实现很可能将消息移动到DLQ,DLQ基本上也是具有自己的侦听器的常规队列。

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.

因此,如果您设置两个队列,Q1和Q2并将Q2配置为Q1的DLQ,您将在Q1上的侦听器中执行正常的请求处理,并为Q2执行额外的侦听器来执行错误/超时处理。

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.

这篇关于JMS超时或TimeToLive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆