简体   繁体   English

会话回滚,回退和死信处理程序

[英]Session rollback, backout and dead-letter handler

I am using MQQueueSession.rollback() to rollback the unit of work. 我正在使用MQQueueSession.rollback()回滚工作单元。 The message is moved to BACKOUT queue, which is all right. 消息被移到BACKOUT队列中,可以了。

The question though is how to handle these messages in backout queue? 但问题是如何在退回队列中处理这些消息? I read that I can use runmqdlq tool but it only works with messages prefixed with MQDLH. 我读到可以使用runmqdlq工具,但它仅适用于以MQDLH为前缀的消息。 Simple MQQueueSession.rollback() doesn't seem to be doing that. 简单的MQQueueSession.rollback()似乎没有这样做。 What am I doing wrong? 我究竟做错了什么?

The code sample: 代码示例:

MQQueueConnection connection;
// ...
MQQueueSession session = (MQQueueSession) connection.createQueueSession(true, Session.SESSION_TRANSACTED);
MQQueue queue = (MQQueue) session.createQueue("queue:///TEST");
MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);
JMSTextMessage message = null;

try {
    message = (JMSTextMessage) receiver.receive();
    // ...
    session.commit();
} catch (JMSException e) {
    session.rollback();
    e.printStackTrace();
}

A message can be backed out by MQ JMS provider to a back out queue or a dead letter queue for few reasons. 出于某些原因,MQ JMS提供程序可以将消息回退到回退队列或死信队列。 Some of them are 他们之中有一些是

1) Badly formatted messages 1)格式错误的邮件
2) Message not acknowledged by the client application either by doing a Commit in a transacted session or Message.Acknowledge() in a client acknowledged session. 2)客户端应用程序未通过在事务处理会话中执行Commit或在客户端已确认会话中执行Message.Acknowledge()来确认消息。 In such case a message is redelivered. 在这种情况下,将重新发送一条消息。 If the same is delivered again and again, MQ JMS provider moves that message to back out queue based on the BOTHRESH setting on the queue. 如果一次又一次传递相同的消息,那么MQ JMS提供程序将根据队列上的BOTHRESH设置将该消息移回队列。

The above is called "Poison Message" handling. 上面称为“中毒消息”处理。

Many a times, a queue may not have a back out queue ( BOQUEUE ) defined. 很多时候,一个队列可能没有定义退出队列( BOQUEUE )。 In such cases MQ JMS provider moves the poison message to a dead letter queue ( DLQ ) prefixing DLQ header. 在这种情况下,MQ JMS提供程序将有害消息移动到以DLQ标头为前缀的死信队列( DLQ )。 You can use runmqdlq to handle messages in a DLQ . 您可以使用runmqdlq处理DLQ消息。

Messages in backout queue do not have any header pre-fixed like DLQ . 退出队列中的消息没有像DLQ这样的DLQ You need to investigate why messages ending up there. 您需要调查为什么消息在那里结束。 Fix the reason(s) and move the message back to original queue so that the message can be delivered to application. 解决原因,然后将消息移回原始队列,以便可以将消息传递到应用程序。

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

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