javascript
ActiveMQ(07):ActiveMQ结合Spring开发--建议
1、Camel框架支持大量的企業(yè)集成模式,可以大大簡化集成組件間的大量服務(wù)和復(fù)雜的消息流。而Spring框架更注重簡單性,僅僅支持基本的最佳實踐。
2、Spring消息發(fā)送的核心架構(gòu)是JmsTemplate,隔離了像打開、關(guān)閉Session和Producer的繁瑣操作,因此應(yīng)用開發(fā)人員僅僅需要關(guān)注實際的業(yè)務(wù)邏輯。
? 但是JmsTemplate損害了ActiveMQ的PooledConnectionFactory對session和消息producer的緩存機制而帶來的性能提升。
3、新的Spring里面,可以設(shè)置org.springframework.jms.connection.CachingConnectionFactory的sessionCacheSize ,或者干脆使用ActiveMQ的
? PooledConnectionFactory,如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 | ????<bean?id="jmsFactory"?class="org.apache.activemq.pool.PooledConnectionFactory"?destroy-method="stop"> ????????<property?name="connectionFactory"> ????????<bean?class="org.apache.activemq.ActiveMQConnectionFactory"> ????????????<property?name="brokerURL"> ????????????<value>${activemq.brokerURL}</value> ????????</property> ????????<property?name="userName"?value="${activemq.userName}"></property> ????????????<property?name="password"?value="${activemq.password}"></property> ????????</bean> ????</property> ????<property?name="maxConnections"?value="${activemq.maxConnections}"></property> ????</bean> |
4、不建議使用JmsTemplate的receive()調(diào)用,因為在JmsTemplate上的所有調(diào)用都是同步的,這意味著調(diào)用線程需要被阻塞,直到方法返回,這對性能影響很大。
5、請使用DefaultMessageListenerContainer,它允許異步接收消息并緩存session和消息consumer,而且還可以根據(jù)消息數(shù)量動態(tài)的增加或縮減監(jiān)聽器的數(shù)量。
| 1 2 3 4 5 6 | <!--?消費者監(jiān)聽器?--> <bean?id="jmsContainer"?class="org.springframework.jms.listener.DefaultMessageListenerContainer"> ????<property?name="connectionFactory"?ref="jmsFactory"?/> ????<property?name="destination"?ref="destinationTopic"?/> ????<property?name="messageListener"?ref="messageListener"?/> </bean> 本文轉(zhuǎn)自我愛大金子博客51CTO博客,原文鏈接http://blog.51cto.com/1754966750/1916382如需轉(zhuǎn)載請自行聯(lián)系原作者 ??我愛大金子 |
總結(jié)
以上是生活随笔為你收集整理的ActiveMQ(07):ActiveMQ结合Spring开发--建议的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html font-family设置无效
- 下一篇: firefox+android+平板,F