ActiveMQ——6.Spring-JmsTemplate特性设置
来源:互联网 发布:如何筛选excel重复数据 编辑:程序博客网 时间:2024/06/05 05:24
概述
这是关于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()
获取接收等待时间,毫秒单位
阅读全文
0 0
- ActiveMQ——6.Spring-JmsTemplate特性设置
- ActiveMQ——4.Spring-JmsTemplate之发送与接收
- ActiveMQ——5.Spring-JmsTemplate之浏览与执行
- 淘淘商城系列——Spring与ActiveMQ的整合及用JmsTemplate发送消息
- activeMQ,spring的jmstemplate简单例子
- activeMQ,spring的jmstemplate简单例子
- activeMQ,spring的jmstemplate简单例子
- activeMQ,spring的jmstemplate简单例子
- activeMQ,spring的jmstemplate简单例子
- activeMQ,spring的jmstemplate简单例子
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate生成和订阅消息(二)
- Spring与ActiveMQ整合及用JmsTemplate发送消息
- ActiveMQ使用spring JmsTemplate发送消息(一)
- activemq的连接池,通过spring的JmsTemplate发送消息到指定的Destination
- activemq的连接池,通过spring的JmsTemplate发送消息到指定的Destination
- 学习淘淘商城第六十课(Spring与Activemq的整合及用JmsTemplate发送消息)
- spring的jmsTemplate
- C#中Serializable序列化实例
- js获取两个时间差
- ROS源码解读(一)--局部路径规划
- okhttp请求数据时报错,输出java.lang.IllegalStateException: closed
- Error: spawn EACCES
- ActiveMQ——6.Spring-JmsTemplate特性设置
- sqlitedeveloper数据库管理(SQLite Developer) v4.0.0.528 中文破解版
- pycharm的快捷键
- TOMCAT性能调优
- Hardware acceleration can only be used with a single UI thread
- zstuoj 4355
- 【Java】8.ConcurrentMap与ConcurrentHashMap
- www的基本用法(一)
- IAR SmartRF04Prog 显示“Could not open the hex-file” 解决方法