【问题标题】:Setting time-to-live to messages in Spring Integration在 Spring Integration 中为消息设置生存时间
【发布时间】:2015-04-08 21:45:15
【问题描述】:

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

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

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

我希望有人可以帮助我! :)

【问题讨论】:

    标签: spring jms spring-integration messaging qpid


    【解决方案1】:

    根据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());
    }
    

    因此,您应该为您的&lt;int-jms:outbound-channel-adapter&gt; 添加explicit-qos-enabled="true"time-to-live="5000"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 2023-03-29
      • 2016-06-14
      相关资源
      最近更新 更多