1、Camel框架支持大量的企業集成模式,可以大大簡化集成組件間的大量服務和復雜的消息流。而Spring框架更注重簡單性,僅僅支持基本的最佳實踐。
2、Spring消息發送的核心架構是JmsTemplate,隔離了像打開、關閉Session和Producer的繁瑣操作,因此應用開發人員僅僅需要關注實際的業務邏輯。
? 但是JmsTemplate損害了ActiveMQ的PooledConnectionFactory對session和消息producer的緩存機制而帶來的性能提升。
3、新的Spring里面,可以設置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()調用,因為在JmsTemplate上的所有調用都是同步的,這意味著調用線程需要被阻塞,直到方法返回,這對性能影響很大。
5、請使用DefaultMessageListenerContainer,它允許異步接收消息并緩存session和消息consumer,而且還可以根據消息數量動態的增加或縮減監聽器的數量。
1 2 3 4 5 6 | <!--?消費者監聽器?--> < 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 > 本文轉自我愛大金子博客51CTO博客,原文鏈接http://blog.51cto.com/1754966750/1916382如需轉載請自行聯系原作者 ??我愛大金子 |