我需要为我的消息设置一个生存时间。
我尝试了以下示例,但生效时间将被忽略。 :/
context.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;
}
}
我希望有人可以帮助我! :)
答案 0 :(得分:5)
根据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>
一起。