When is it appropriate to cacheConsumers when using Spring CachingConnectionFactory?

被刻印的时光 ゝ 提交于 2019-12-11 10:20:44

问题


Spring includes a class called CachingConnectionFactory. One variable in this class is a boolean named cacheProducers. By default, this value is true. This variable can be set to false using setCacheProducers(false).

When would it be appropriate to set this to false? What are the benefits and drawbacks of setting to false?

Background: We are conducting a performance test of our application and use Spring JMS to post thousands of messages a second to JMS. Profiling our code, we see that the session.createProducer call is consuming over 60% of our total processing time and the factory is currently set to setCacheProducers(false). What are the consequences to setting this value to true?


回答1:


Setting it to false pretty much defeats the whole purpose. You are left with simply caching the connection.

You might want to set it to false if you want to manage the producer lifecycle yourself (e.e. when using execute() with a SessionCallback). But when you are using the higher level abstractions (send(), convertAndSend() etc), you would generally want it to be true.

This is for the Jmstemplate. It is generally not recommended to use a CachingConnectionFactory with the DefaultMessageListenerContainer.



来源:https://stackoverflow.com/questions/22672419/when-is-it-appropriate-to-cacheconsumers-when-using-spring-cachingconnectionfact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!