使用JmsTemplate发送持久化和非持久化消息

由于JmsTemplate内部发送消息默认为持久化的,所以不用设置即可发送持久化消息。

如果要发送非持久化的消息,请按照以下配置即可:

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<!-- 其他配置 -->
		<property name="deliveryMode" value="1"></property>
		<property name="explicitQosEnabled" value="true"></property>
	</bean>

对于发送非持久化消息需要配置explicitQosEnabled该属性为true,否则spring内部发送消息时将采用默认配置进行发送消息,

而spring内部默认为持久化发送,所以上述属性必须设置为true,当设置为true时,外部设置的属性才可以使用。


下面为属性explicitQosEnabled的注释信息,如下:

	/**
	 * If "true", then the values of deliveryMode, priority, and timeToLive
	 * will be used when sending a message. Otherwise, the default values,
	 * that may be set administratively, will be used.
	 * @return true if overriding default values of QOS parameters
	 * (deliveryMode, priority, and timeToLive)
	 * @see #setDeliveryMode
	 * @see #setPriority
	 * @see #setTimeToLive
	 */
	public boolean isExplicitQosEnabled() {
		return this.explicitQosEnabled;
	}

下面是发送消息的地方,如下代码所示:

protected void doSend(MessageProducer producer, Message message) throws JMSException {
		if (isExplicitQosEnabled()) {
			producer.send(message, getDeliveryMode(), getPriority(), getTimeToLive());
		}
		else {
			producer.send(message);
		}
	}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值