哪个更好:PooledConnectionFactory或CachingConnectionFactory?

时间:2021-12-19 12:47:34

We use Spring (3.2.4) with ActiveMQ (5.8.0) in Tomcat (7.0.41) and it is not clear what the best usage. We want to use JmsTemplate to produce and MessageListenerContainer to receive messages.

Should we use caching in receiver side? (related link)
Works CachingConnectionFactory with ActiveMQ and failover? (related link)
Need to set useAsyncSend="true" when we use PooledConnectionFactory? (related link)

我们在Tomcat(7.0.41)中使用Spring(3.2.4)和ActiveMQ(5.8.0)并且不清楚最佳用法是什么。我们希望使用JmsTemplate生成MessageListenerContainer来接收消息。我们应该在接收方使用缓存吗? (相关链接)使用ActiveMQ和故障转移工作CachingConnectionFactory? (相关链接)当我们使用PooledConnectionFactory时,需要设置useAsyncSend =“true”吗? (相关链接)

1 个解决方案

#1


32  

From here:

从这里:

The difference between the PooledConnectionFactory and the CachingConnectionFactory is a difference in implementation. Below are some of the characteristics that differ between them:

PooledConnectionFactory和CachingConnectionFactory之间的区别在于实现上的差异。以下是它们之间不同的一些特征:

  • Although both the PooledConnectionFactory and the CachingConnectionFactory state that they each pool connections, sessions and producers, the PooledConnectionFactory does not actually create a cache of multiple producers. It simply uses a singleton pattern to hand out a single cached producer when one is requested. Whereas the CachingConnectionFactory actually creates a cache containing multiple producers and hands out one producer from the cache when one is requested.

    尽管PooledConnectionFactory和CachingConnectionFactory都声明它们各自汇集了连接,会话和生成器,但PooledConnectionFactory实际上并不创建多个生成器的缓存。当请求一个缓存生成器时,它只使用单例模式分发单个缓存生成器。而CachingConnectionFactory实际上创建了一个包含多个生成器的缓存,并在请求一个生成器时从缓存中分发出一个生成器。

  • The PooledConnectionFactory is built on top of the Apache Commons Pool project for pooling JMS sessions. This allows some additional control over the pool because there are features in Commons Pool that are not being used by the PooledConnectionFactory. These additional features include growing the pool size instead of blocking, throwing an exception when the pool is exhausted, etc. You can utilize these features by creating your own Commons Pool GenericObjectPool using your own customized settings and then handing that object to the PooledConnectionFactory via the setPoolFactory method. See the following for additional info: http://commons.apache.org/pool/api-1.4/org/apache/commons/pool/impl/GenericObjectPoolFactory.html

    PooledConnectionFactory构建在Apache Commons Pool项目之上,用于池化JMS会话。这允许对池进行一些额外的控制,因为Commons Pool中的功能没有被PooledConnectionFactory使用。这些附加功能包括增加池大小而不是阻塞,在池耗尽时抛出异常等。您可以使用自己的自定义设置创建自己的Commons Pool GenericObjectPool,然后通过以下方法将该对象交给PooledConnectionFactory来利用这些功能。 setPoolFactory方法。有关其他信息,请参阅以下内容:http://commons.apache.org/pool/api-1.4/org/apache/commons/pool/impl/GenericObjectPoolFactory.html

  • The CachingConnectionFactory has the ability to also cache consumers. Just need to take care when using this feature so that you know the consumers are cached according to the rules noted in the blog post.

    CachingConnectionFactory还能够缓存使用者。使用此功能时需要注意,以便您知道根据博客文章中提到的规则缓存消费者。

  • But most importantly, the CachingConnectionFactory will work with any JMS compliant MOM. It only requires a JMS connection factory. This is important if you are using more than one MOM vendor which is very common in enterprise organizations (this is mainly due to legacy and existing projects). The important point is that the CachingConnectionFactory works very well with many different MOM implementations, not only ActiveMQ.

    但最重要的是,CachingConnectionFactory可以与任何符合JMS的MOM一起使用。它只需要一个JMS连接工厂。如果您使用的是多个MOM供应商,这在企业组织中非常常见(这主要是由于遗留项目和现有项目),这一点非常重要。重要的一点是,CachingConnectionFactory可以很好地与许多不同的MOM实现配合使用,而不仅仅是ActiveMQ。

From here:

从这里:

  • If you have clustered ActiveMQs, and use failover transport it has been reported that CachingConnectionFactory is not a right choice.

    如果您有群集的ActiveMQ,并使用故障转移传输,则报告CachingConnectionFactory不是正确的选择。

  • The problem I’m having is that if one box goes down, we should start sending messages on the other, but it seems to still be using the old connection (every send times out). If I restart the program, it’ll connect again and everything works. Source: Autoreconnect problem with ActiveMQ and CachingConnectionFactory

    我遇到的问题是,如果一个盒子出现故障,我们应该开始在另一个盒子上发送消息,但它似乎仍在使用旧连接(每次发送超时)。如果我重新启动程序,它将再次连接,一切正常。来源:ActiveMQ和CachingConnectionFactory的自动连接问题

  • The problem is that cached connections to the failed ActiveMQ was still in use and that created the problem for the user. Now, the choice for this scenario is PooledConnectionFactory.

    问题是与失败的ActiveMQ的缓存连接仍在使用中,并为用户创建了问题。现在,这种情况的选择是PooledConnectionFactory。

  • If you’re using ActiveMQ today, and chances are that you may switch to some other broker (JBoss MQ, WebSphere MQ) in future, do not use PooledConnectionFactory, as it tightly couples your code to ActiveMQ.

    如果您今天正在使用ActiveMQ,并且将来可能会切换到其他代理(JBoss MQ,WebSphere MQ),请不要使用PooledConnectionFactory,因为它会将您的代码紧密耦合到ActiveMQ。

#1


32  

From here:

从这里:

The difference between the PooledConnectionFactory and the CachingConnectionFactory is a difference in implementation. Below are some of the characteristics that differ between them:

PooledConnectionFactory和CachingConnectionFactory之间的区别在于实现上的差异。以下是它们之间不同的一些特征:

  • Although both the PooledConnectionFactory and the CachingConnectionFactory state that they each pool connections, sessions and producers, the PooledConnectionFactory does not actually create a cache of multiple producers. It simply uses a singleton pattern to hand out a single cached producer when one is requested. Whereas the CachingConnectionFactory actually creates a cache containing multiple producers and hands out one producer from the cache when one is requested.

    尽管PooledConnectionFactory和CachingConnectionFactory都声明它们各自汇集了连接,会话和生成器,但PooledConnectionFactory实际上并不创建多个生成器的缓存。当请求一个缓存生成器时,它只使用单例模式分发单个缓存生成器。而CachingConnectionFactory实际上创建了一个包含多个生成器的缓存,并在请求一个生成器时从缓存中分发出一个生成器。

  • The PooledConnectionFactory is built on top of the Apache Commons Pool project for pooling JMS sessions. This allows some additional control over the pool because there are features in Commons Pool that are not being used by the PooledConnectionFactory. These additional features include growing the pool size instead of blocking, throwing an exception when the pool is exhausted, etc. You can utilize these features by creating your own Commons Pool GenericObjectPool using your own customized settings and then handing that object to the PooledConnectionFactory via the setPoolFactory method. See the following for additional info: http://commons.apache.org/pool/api-1.4/org/apache/commons/pool/impl/GenericObjectPoolFactory.html

    PooledConnectionFactory构建在Apache Commons Pool项目之上,用于池化JMS会话。这允许对池进行一些额外的控制,因为Commons Pool中的功能没有被PooledConnectionFactory使用。这些附加功能包括增加池大小而不是阻塞,在池耗尽时抛出异常等。您可以使用自己的自定义设置创建自己的Commons Pool GenericObjectPool,然后通过以下方法将该对象交给PooledConnectionFactory来利用这些功能。 setPoolFactory方法。有关其他信息,请参阅以下内容:http://commons.apache.org/pool/api-1.4/org/apache/commons/pool/impl/GenericObjectPoolFactory.html

  • The CachingConnectionFactory has the ability to also cache consumers. Just need to take care when using this feature so that you know the consumers are cached according to the rules noted in the blog post.

    CachingConnectionFactory还能够缓存使用者。使用此功能时需要注意,以便您知道根据博客文章中提到的规则缓存消费者。

  • But most importantly, the CachingConnectionFactory will work with any JMS compliant MOM. It only requires a JMS connection factory. This is important if you are using more than one MOM vendor which is very common in enterprise organizations (this is mainly due to legacy and existing projects). The important point is that the CachingConnectionFactory works very well with many different MOM implementations, not only ActiveMQ.

    但最重要的是,CachingConnectionFactory可以与任何符合JMS的MOM一起使用。它只需要一个JMS连接工厂。如果您使用的是多个MOM供应商,这在企业组织中非常常见(这主要是由于遗留项目和现有项目),这一点非常重要。重要的一点是,CachingConnectionFactory可以很好地与许多不同的MOM实现配合使用,而不仅仅是ActiveMQ。

From here:

从这里:

  • If you have clustered ActiveMQs, and use failover transport it has been reported that CachingConnectionFactory is not a right choice.

    如果您有群集的ActiveMQ,并使用故障转移传输,则报告CachingConnectionFactory不是正确的选择。

  • The problem I’m having is that if one box goes down, we should start sending messages on the other, but it seems to still be using the old connection (every send times out). If I restart the program, it’ll connect again and everything works. Source: Autoreconnect problem with ActiveMQ and CachingConnectionFactory

    我遇到的问题是,如果一个盒子出现故障,我们应该开始在另一个盒子上发送消息,但它似乎仍在使用旧连接(每次发送超时)。如果我重新启动程序,它将再次连接,一切正常。来源:ActiveMQ和CachingConnectionFactory的自动连接问题

  • The problem is that cached connections to the failed ActiveMQ was still in use and that created the problem for the user. Now, the choice for this scenario is PooledConnectionFactory.

    问题是与失败的ActiveMQ的缓存连接仍在使用中,并为用户创建了问题。现在,这种情况的选择是PooledConnectionFactory。

  • If you’re using ActiveMQ today, and chances are that you may switch to some other broker (JBoss MQ, WebSphere MQ) in future, do not use PooledConnectionFactory, as it tightly couples your code to ActiveMQ.

    如果您今天正在使用ActiveMQ,并且将来可能会切换到其他代理(JBoss MQ,WebSphere MQ),请不要使用PooledConnectionFactory,因为它会将您的代码紧密耦合到ActiveMQ。