2015-02-09 51 views
1

我需要为我的消息设置生存时间。在Spring集成中将消息的生存时间设置为

我尝试了下面的例子,但生存时间将被忽略。 :/

的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; 
    } 
} 

我希望有人能帮帮我! :)

回答

4

根据JmsTemplate JavaDoc中我们有:

/** 
* 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; 
} 

所以,如果explicitQosEnabledtrueJmsTemplate#doSend)它不工作:

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

因此,你应该与用添加explicit-qos-enabled="true"time-to-live="5000"为您的<int-jms:outbound-channel-adapter>

+0

谢谢你......它工作:) – Smoothi 2015-02-09 08:16:15

相关问题