gpt4 book ai didi

spring-integration - Spring 集成捕获 JMSTemplate 生存时间超时

转载 作者:行者123 更新时间:2023-12-04 07:54:34 24 4
gpt4 key购买 nike

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

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

我以为我可以有某种形式:

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

2)WireTap,但我认为这意味着使用计时器阻塞发件人(请求/响应模型)上的线程,该计时器监视要被远程客户端删除的消息。我再次不确定如何实现这一点。

非常感谢有关如何最好地实现上述内容的任何帮助。

进度报告:
我尝试使用方法 JMSTemplate.receiveSelected(destination, messageSelector); 查询 MQ Artem Bilan 建议的。计划是手动查找在给定时间内未被客户端使用的消息。 (提供者必须跟踪所有消息,并在计时器到期后尝试使用其 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 集成捕获 JMSTemplate 生存时间超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45146150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com