ActiveMQ pooled Connection Factory for multiple durable subscribers

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ActiveMQ pooled Connection Factory for multiple durable subscribers

Steven Turner
Hi ActiveMQ Gods,

I am trying to implement a scenario where I have to create multiple durable subscribers in the same application. I want to use spring default messages listener container with ActiveMQ pooled connection factory where "maxConnection" specified to the required number of connections.

But I was going through some posts which are saying not to use pooling for durable subscriber :

http://activemq.2283324.n4.nabble.com/durable-topic-subscriber-using-spring-and-atomikos-td3209848.html 
http://osdir.com/ml/java.activemq.user/2005-05/msg00141.html 

And I have also seen lot of posts recently about this. So my question is :
Should a client use the above specified configuration (pooledConnectionFactory with maxConnection specified for multiple durable subscriber) in an application.

IF not then what is the correct way to configure this type of test cases?




Thanks,
Steven
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ pooled Connection Factory for multiple durable subscribers

Steven Turner
This post was updated on .
FYI: This is how my configuration looks like:

      <bean id="ConnFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
      destroy-method="stop">
      <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
      <property name="brokerURL">
      <value>${mybroker.url}</value>
      </property>
      </bean>
      </property>
      <property name="maxConnections" value="4" />
     
and my listener is using it as:
   <bean id="listenerContainer1"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
          <property name="connectionFactory" ref="ConnFactory" />
          <property name="destination" ref="test.1" />
          <property name="durableSubscriptionName" value="test1" />
          <property name="pubSubDomain" value="true" />
          <property name="subscriptionDurable" value="true" />
          <property name="clientId" value="test1" />
          <property name="messageListener" ref="MessageListener" />
     </bean>

 <bean id="listenerContainer2"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
          <property name="connectionFactory" ref="ConnFactory" />
          <property name="destination" ref="test.2" />
          <property name="durableSubscriptionName" value="test2" />
          <property name="pubSubDomain" value="true" />
          <property name="subscriptionDurable" value="true" />
          <property name="clientId" value="test2" />
          <property name="messageListener" ref="MessageListener2" />
     </bean>
 <bean id="listenerContainer3"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
          <property name="connectionFactory" ref="ConnFactory" />
          <property name="destination" ref="test.3" />
          <property name="durableSubscriptionName" value="test3" />
          <property name="pubSubDomain" value="true" />
          <property name="subscriptionDurable" value="true" />
          <property name="clientId" value="test3" />
          <property name="messageListener" ref="MessageListener3" />
     </bean>
 <bean id="listenerContainer4"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
          <property name="connectionFactory" ref="ConnFactory" />
          <property name="destination" ref="test.4" />
          <property name="durableSubscriptionName" value="test4" />
          <property name="pubSubDomain" value="true" />
          <property name="subscriptionDurable" value="true" />
          <property name="clientId" value="test4" />
          <property name="messageListener" ref="MessageListener4" />
     </bean>
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ pooled Connection Factory for multiple durable subscribers

artnaseef
My recommendation is to start simple and add complexity as-needed.

What does a pooled connection add to the solution?  If nothing, remove it.  In general, pooled connections are useful for two key concerns:

- Processing flows which do not keep connections for long periods (e.g. open connection / process 1 msg / close connection)
- Clients with a fair-to-large number of consumers to various destinations; pooling here helps to share resources across consumers (e.g. 100 consumers on 10 connections) -- at the cost of reduced throughput.

Durable subscriptions do not play well with pooled connections.  In that case, use individual connections.  Using a pool with max connections set to 1 may work to reuse the connection across mutiple consumers - I haven't tried it.

In the posted config, remove the pooled connection factory.  The multiple client IDs are fatal.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ pooled Connection Factory for multiple durable subscribers

Matt Pavlovich-2
In reply to this post by Steven Turner
I don’t recommend using pools for consumers, until you have a specific scenario that a single connection per consumer doesn’t fit your needs. Pre-tuning usually results in de-tuning when it comes to messaging.

Start with a single connection and single consumer and measure performance there.  Most applications will perform as needed with that configuration.

As far as multiple durable subscriptions— I suggest looking at using Virtual Topics instead.  Durable Subscribers are one of the painful leftovers from JMS 1.1 that we are stuck with, but ActiveMQ made Virtual Topics so we aren’t forced to suffer =)

On Aug 19, 2014, at 2:28 AM, Steven Turner <[hidden email]> wrote:

> FYI: This is how my configuration looks like:
>
>      <bean id="ConnFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
>      destroy-method="stop">
>      <property name="connectionFactory">
>      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>      <property name="brokerURL">
>      <value>${mybroker.url}</value>
>      </property>
>      </bean>
>      </property>
>      <property name="maxConnections" value="4" />
>
> and my listener is using it as:
>   <bean id="listenerContainer"
>
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>          <property name="connectionFactory" ref="ConnFactory" />
>          <property name="destination" ref="test.1" />
>          <property name="durableSubscriptionName" value="test1" />
>          <property name="pubSubDomain" value="true" />
>          <property name="subscriptionDurable" value="true" />
>          <property name="clientId" value="test1" />
>          <property name="messageListener" ref="MessageListener" />
>     </bean>
>
> <bean id="listenerContainer"
>
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>          <property name="connectionFactory" ref="ConnFactory" />
>          <property name="destination" ref="test.2" />
>          <property name="durableSubscriptionName" value="test2" />
>          <property name="pubSubDomain" value="true" />
>          <property name="subscriptionDurable" value="true" />
>          <property name="clientId" value="test2" />
>          <property name="messageListener" ref="MessageListener2" />
>     </bean>
> <bean id="listenerContainer"
>
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>          <property name="connectionFactory" ref="ConnFactory" />
>          <property name="destination" ref="test.3" />
>          <property name="durableSubscriptionName" value="test3" />
>          <property name="pubSubDomain" value="true" />
>          <property name="subscriptionDurable" value="true" />
>          <property name="clientId" value="test3" />
>          <property name="messageListener" ref="MessageListener3" />
>     </bean>
> <bean id="listenerContainer"
>
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>          <property name="connectionFactory" ref="ConnFactory" />
>          <property name="destination" ref="test.4" />
>          <property name="durableSubscriptionName" value="test4" />
>          <property name="pubSubDomain" value="true" />
>          <property name="subscriptionDurable" value="true" />
>          <property name="clientId" value="test4" />
>          <property name="messageListener" ref="MessageListener4" />
>     </bean>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-pooled-Connection-Factory-for-multiple-durable-subscribers-tp4684735p4684736.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: ActiveMQ pooled Connection Factory for multiple durable subscribers

artnaseef
I agree that a single connection per consumer is a good starting point.  Be mindful of overall connection counts on the server though, and be sure to use the NIO connector if those counts will be high on the broker (in the thousands rather than hundreds).  Make sure to count connections from all clients to the individual broker.