gpt4 book ai didi

spring - 在 Spring Integration 中设置消息的生存时间

转载 作者:行者123 更新时间:2023-12-02 11:49:38 24 4
gpt4 key购买 nike

我需要设置我的消息的生存时间。

我尝试了以下示例,但生存时间将被忽略。 :/

上下文.xml

<int:channel id="publishChannel"/>

<int-jms:outbound-channel-adapter
channel="publishChannel"
destination="defaultDestination"
time-to-live="5000"
pub-sub-domain="false" />

出版商

import org.springframework.integration.annotation.Publisher;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Service;

@Service("publishService")
public class PublishService{
private MessageChannel messageChannel;

@Publisher(channel = "publishChannel")
public Message<?> sendMessage (Message<?> message) {
return message;
}
}

希望有人能帮助我! :)

最佳答案

根据JmsTemplate我们有 JavaDocs:

/**
* Set the time-to-live of the message when sending.
* <p>Since a default value may be defined administratively,
* this is only used when "isExplicitQosEnabled" equals "true".
* @param timeToLive the message's lifetime (in milliseconds)
* @see #isExplicitQosEnabled
* @see javax.jms.Message#DEFAULT_TIME_TO_LIVE
* @see javax.jms.MessageProducer#send(javax.jms.Message, int, int, long)
*/
public void setTimeToLive(long timeToLive) {
this.timeToLive = timeToLive;
}

所以,如果 explicitQosEnabled 则不起作用。不是true (JmsTemplate#doSend):

if (isExplicitQosEnabled()) {
producer.send(message, getDeliveryMode(), getPriority(), getTimeToLive());
}

因此您应该添加 explicit-qos-enabled="true"time-to-live="5000"一起为您<int-jms:outbound-channel-adapter> .

关于spring - 在 Spring Integration 中设置消息的生存时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28404923/

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