我有发送到IBM MQ队列的JMS消息,如果远程客户机(我无法控制远程客户机)在给定的时间(例如1分钟)内不使用该消息,则该消息应该过期(我具有Expire)部分工作,使用JMSTemplate上的setExplicitQosEnabled和setTimeToLive进行“ MQ删除消息”,并且应通知消息发送者(我的SI代码)该消息未传递到远程客户端,以便可以将过期的消息重新路由到另一个队列。

我不确定如何使用Spring Integration实现这种模式,尤其是消息是异步发送的,并且仅在返回时才相关(MessageID-> CorrelationID)。

我以为我可以采用以下形式:

1)ErrorMessageExceptionTypeRouter,但是我需要有效负载,因此我可以重新发送消息,而且我不确定如何实现此方法(如何从MQ回调到JMSTemplate或在超时时路由到另一个队列,并有一个辅助路由侦听该消息排队并重新路由)

2)WireTap,但是我认为这意味着使用计时器来阻止发件人(请求/响应模型)上的线程,该计时器监视远程客户端要删除的msg。同样,我不确定如何执行此操作。

非常感谢您对如何最好地实施上述帮助。

进度报告:
我尝试使用Artem Bilan建议的方法JMSTemplate.receiveSelected(destination, messageSelector);来查询MQ。计划是在给定时间内手动查找客户端尚未使用的消息。 (提供商必须跟踪所有消息,并在计时器到期后尝试使用其messageID来检索每条消息,而不是使用TimeToLive消息到期)。此解决方案使提供商有责任跟踪和计时发送的每条消息并尝试检索每条消息(大多数消息不可用)使其效率低下,但却是可行的解决方案。不幸的是,当我打电话时,IBM MQ不喜欢它:JMSTemplate.receiveSelected(destination, messageSelector);我收到以下错误:

org.springframework.jms.InvalidSelectorException: JMSWMQ2008: Failed to open MQ queue ‘MY.TEST.IN'.; nested exception is com.ibm.msg.client.jms.DetailedInvalidSelectorException: JMSWMQ2008: Failed to open MQ queue 'MY.TEST.IN'.JMS attempted to perform an MQOPEN, but WebSphere MQ reported an error.Use the linked exception to determine the cause of this error. Check that the specified queue and queue manager are defined correctly.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2459' ('MQRC_SELECTOR_SYNTAX_ERROR').

但是,将JMSTemplate.receive(destination);与相同的目标一起使用不会从队列中读取消息。

最佳答案

以下代码使IBM MQ V8自动将已过期的消息重新路由到JMSReplyTo队列,(感谢JoshMc在上面的评论中的建议)

jmsTemplate.setTimeToLive(3000l);
jmsTemplate.setExplicitQosEnabled(true);
jmsTemplate.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);
jmsTemplate.setPriority(Message.DEFAULT_PRIORITY);
jmsTemplate.send(destinationName, session -> {
    TextMessage toSend = session.createTextMessage(message)
    toSend.setIntProperty("JMS_IBM_Report_Expiration", 14680064);
    Queue queue = session.createQueue(“TEST.EXPIRE.REPORT”);
    toSend.setJMSReplyTo(queue);

    return toSend;
});


我在这里找到的JMS_IBM_Report_Expiration值为14680064:https://www.ibm.com/support/knowledgecenter/en/SS7K4U_8.0.0/com.ibm.websphere.javadoc.doc/web/apidocs/constant-values.html#com.ibm.websphere.sib.api.jms.ApiJmsConstants.MQRO_EXPIRATION_WITH_FULL_DATA

我需要找到此JAR并将其添加到我的项目中,但是MQ删除了过期的消息并将其存储在我指定的对队列的答复中。

关于spring-integration - Spring Integration捕获JMSTemplate生存时间超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45146150/

10-09 00:45
查看更多