ActiveMQ——6.Spring-JmsTemplate特性设置
2017-12-11 14:06
591 查看
概述
这是关于JmsTemplate的最后一篇总结,且只会介绍几个比较重要的特性。
消息的递送模式
在发送消息给时,可以告知这是持久化的消息,还是非持久化的消息。如果是非持久化的消息,broker会将消息保留在内存,否则就会持久化到磁盘。非持久化:高吞吐,易丢失;持久化:低吞吐,不易丢失。相关的API:
Class org.springframework.jms.core.JmsTemplate |
public void setDeliveryMode(int deliveryMode) 设置是否持久化要发送的消息:1-非持久化;2-持久化 public int getDeliveryMode() 获取持久化模式的设置:1-非持久化;2-持久化 public void setDeliveryPersistent(boolean deliveryPersistent) 设置是否持久化要发送的消息,true-持久化;false-非持久化 |
消息的优先级
在发送时,可以为消息指定优先级,以期高优先级的消息能更快的递送给consumer。在javax.jms.Message#getJMSPriority()方法,有如下的说明:JMS API为消息定义了10个优先级,0最低,9最高。0-4作为一般的优先级,5-9作为加速优先级。JMS API不要求实现者能够严格按照消息的优先级的顺序把消息递送给consumer,但是应该尽量的实现加速优先级的消息能在一般优先级的消息的前面,递送给consumer。
下面是JmsTemplate中的API:
Class org.springframework.jms.core.JmsTemplate |
public void setPriority(int priority) 为将要发送的消息设置优先级。 public int getPriority() 获取优先级 |
消息的存活时间
在发送时,可以设置消息的存活时间,默认为永久有效。Class org.springframework.jms.core.JmsTemplate |
public void setTimeToLive(long timeToLive) 设置消息的存活时间,毫秒单位 public long getTimeToLive() 获取消息的存活时间,毫秒单位 |
服务质量开关
如果不打开服务质量的开关,消息的递送模式、优先级和存活时间的设置就没有作用。Class org.springframework.jms.core.JmsTemplate |
public void setExplicitQosEnabled(boolean explicitQosEnabled) 发送消息的时候,是否使用QOS的值(deliveryMode, priority, timeToLive) public boolean isExplicitQosEnabled() 如果是true,deliveryMode, priority, 和 timeToLive的值将被使用;否则使用默认的值。 |
在JMS API中,消息的递送模式、优先级和存活时间可以在发送的时候统一设置:
javax.jms.MessageProducer#send(Message message, int deliveryMode, int priority, long timeToLive):void
接收等待时间
JmsTemplate的接收是阻塞式的接收,默认会一直阻塞等待,直到接收到了消息。也可以设置一个最长的等待时间参数,超过这个时间,接收的方法将得到null的结果。Class org.springframework.jms.core.JmsTemplate |
public void setReceiveTimeout(long receiveTimeout) 设置接收等待时间,毫秒单位 public long getReceiveTimeout() 获取接收等待时间,毫秒单位 |
相关文章推荐
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ACTIVEMQ设置Timestamp和jms简介
- activeMQ,spring的jmstemplate简单例子
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- activeMQ,spring的jmstemplate简单例子
- 淘淘商城系列——Spring与ActiveMQ的整合及用JmsTemplate发送消息
- activeMQ,spring的jmstemplate简单例子
- springboot 整合 activemq,JmsMessagingTemplate注入失败
- JmsTemplate sendAndReceive 设置超时
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ——5.Spring-JmsTemplate之浏览与执行
- activeMQ,spring的jmstemplate简单例子
- ActiveMQ使用spring JmsTemplate发送消息(一)
- activeMQ,spring的jmstemplate简单例子
- ActiveMQ使用spring JmsTemplate发送消息(一)
- activemq设置Timestamp和jms简介