Smo*_*thi 2 messaging spring jms spring-integration qpid
我需要为邮件设置生存时间。
我尝试了以下示例,但是生存时间将被忽略。:/
context.xml
<int:channel id="publishChannel"/>
<int-jms:outbound-channel-adapter
channel="publishChannel"
destination="defaultDestination"
time-to-live="5000"
pub-sub-domain="false" />
Run Code Online (Sandbox Code Playgroud)
发行人
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有一个人可以帮助我!:)
根据JmsTemplateJavaDocs,我们有:
/**
* 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;
}
Run Code Online (Sandbox Code Playgroud)
因此,如果explicitQosEnabled不是true(JmsTemplate#doSend),则不起作用:
if (isExplicitQosEnabled()) {
producer.send(message, getDeliveryMode(), getPriority(), getTimeToLive());
}
Run Code Online (Sandbox Code Playgroud)
因此,你应该添加explicit-qos-enabled="true"一起与time-to-live="5000"你的<int-jms:outbound-channel-adapter>。