使用Spring CachingConnectionFactory时何时适合cacheConsumers? [英] When is it appropriate to cacheConsumers when using Spring CachingConnectionFactory?

查看:275
本文介绍了使用Spring CachingConnectionFactory时何时适合cacheConsumers?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring包含一个名为CachingConnectionFactory的类.此类中的一个变量是一个名为cacheProducers的布尔值.默认情况下,此值为true.可以使用setCacheProducers(false)将此变量设置为false.

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).

何时将其设置为false是合适的? 设置为false有什么好处和缺点?

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

背景: 我们正在对我们的应用程序进行性能测试,并使用Spring JMS将每秒数千条消息发布到JMS.对我们的代码进行性能分析,我们看到session.createProducer调用消耗了我们总处理时间的60%以上,并且工厂当前设置为setCacheProducers(false).将此值设置为true有什么后果?

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?

推荐答案

将其设置为false几乎无法达到目的.您只需要简单地缓存连接即可.

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

如果您想自己管理生产者生命周期(例如,将execute()SessionCallback一起使用时),可能需要将其设置为false.但是,当您使用更高级别的抽象(send()convertAndSend()等)时,通常希望它是真实的.

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.

这是针对Jmstemplate的.通常不建议将CachingConnectionFactoryDefaultMessageListenerContainer一起使用.

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

这篇关于使用Spring CachingConnectionFactory时何时适合cacheConsumers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆