You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by oseymen <oz...@tdpg.com> on 2011/09/12 12:50:22 UTC

Camel - PooledConnectionFactory or not

Hi all,
I am trying to understand the most optimised way to send messages
concurrently between two activemq endpoints using Camel. There has been some
discussions on this in the mail groups but some of them confuses me even
more. So I am looking the draw the line under this topic and get your
recommendations on how to configure them for efficient use.

ActiveMQ documentation (http://camel.apache.org/activemq.html - Using
connection pooling) recommends using PooledConnectionFactory together with
camel's ActiveMQComponent in order to pool connections, sessions and
producers. Camel in Action book recommends using camel ActiveMQComponent and
notes that it configures connection pooling automatically for improved
performance (page 198) and does not mention PooledConnectionFactory at all.
So should I assume that camel's ActiveMQComponent does not pool sessions and
producers?

Furthermore, considering the example in AMQ documentation page above:

<bean id="jmsConnectionFactory" 
   class="org.apache.activemq.ActiveMQConnectionFactory">
   <property name="brokerURL" value="tcp://localhost:61616" />
</bean>

<bean id="pooledConnectionFactory" 
   class="org.apache.activemq.pool.PooledConnectionFactory">
   <property name="maxConnections" value="8" />
   <property name="maximumActive" value="500" />
   <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
   <property name="connectionFactory" ref="pooledConnectionFactory"/>
   <property name="transacted" value="false"/>
   <property name="concurrentConsumers" value="10"/>
</bean>

<bean id="B1" 
    class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
</bean>

With a route configuration like this where messages are moved from B1
(configured above) and some other activemq instance B2:
<route>
	<from uri="B1:Q1" />
	<to uri="B2:Q1" />
</route>

My questions are:
1. Where can I control the number of producers pooled in
PooledConnectionFactory? Does it create and pool one producer per session
(maximumActive setting above)? 
 
2. So if PooledConnectionFactory doesn't pool consumers, isn't it always
inefficient to use PooledConnectionFactory for B1 and efficient for B2?  Or
is it always more efficient to configure both endpoints (B1 and B2) with
PooledConnectionFactory?

Based on your experiences, can you advice when to use
PooledConnectionFactory and any tradeoffs you are aware of please?

Apologies if this is too long a mail but I'd appreciate any info/advice you
can give.

Regards,
Ozan

--
View this message in context: http://activemq.2283324.n4.nabble.com/Camel-PooledConnectionFactory-or-not-tp3807064p3807064.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Camel - PooledConnectionFactory or not

Posted by oseymen <oz...@tdpg.com>.
Thanks for your reply Jason!

That link you provided recommends the use of PooledConnectionFactory if I am
publishing messages - which is OK for B2 endpoint in my above example and
recommends using MessageListenerContainer for consuming messages which is
for B1 endpoint. This also correlates to an old user group reply from James
Strachan saying that PooledConnectionFactory is optimized for producing and
not for consuming.

However I can't find any examples of using MessageListenerContainer in Camel
with Spring DSL (camel.xml). Do you guys have any examples of properly
setting up the ActiveMQ queue consuming endpoint in Camel Spring DSL?

Cheers,
Ozan

--
View this message in context: http://activemq.2283324.n4.nabble.com/Camel-PooledConnectionFactory-or-not-tp3807064p3807470.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Camel - PooledConnectionFactory or not

Posted by Jason Whaley <ja...@gmail.com>.
> 
> 
> My questions are:
> 1. Where can I control the number of producers pooled in
> PooledConnectionFactory? Does it create and pool one producer per session
> (maximumActive setting above)? 

You can't really enforce the maximum number producers you actually have created, since a session can potentially have numerous producer objects.  You can only really enforce the maximum number of sessions, which you've set in "maximumActive".  Under your current configuration you are potentially allowing yourself to have up to 4000 sessions.


> 
> 2. So if PooledConnectionFactory doesn't pool consumers, isn't it always
> inefficient to use PooledConnectionFactory for B1 and efficient for B2?  Or
> is it always more efficient to configure both endpoints (B1 and B2) with
> PooledConnectionFactory?


It's typically better to have a single connection for consumers since those are expected to be long lived connections and you avoid the overhead of having several connections exist for the purpose of pooling.  The JMS and ActiveMQ Camel components use Spring's JmsTemplate under the hood - see http://activemq.apache.org/jmstemplate-gotchas.html .  That page recommends using Spring's CachingConnectionFactory for consumers since that doesn't cache a connection pool but caches session objects instead.