You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Tim Bain <tb...@alumni.duke.edu> on 2016/03/01 04:24:45 UTC

Re: Production ConnectionFactory configuration with Spring

I'd say using a PooledConnectionFactory is a far more common configuration
in production environments than using SingleConnectionFactory.  Allowing
each application to use anywhere from 0 to M (pool size) connections based
on its current load sounds better than having N apps using 1 connection
each or N apps sharing 1 connection total.

I would imagine that you could share it across multiple webapps via JNDI,
though I've never done that myself.
On Feb 29, 2016 3:36 PM, "itelleria" <te...@gmail.com> wrote:

> Hi,
>
> I'm developing some web applications which send/receive messages to/from an
> ActiveMq broker. The ActiveMQ broker is standalone, so it is not embedded
> inside the application. The application is developed with Spring Framework
> and will be deployed in a Java EE Application Server (such as WebSphere).
> I'm considering using Spring JMS instead of Message Drive Beans (MDB) in
> order not to tie the application to an Application Server due to the use of
> MDBs.
>
> I've got some doubts about how the connectionFactory should be configured.
>
> I've installed the Resource Adapter of ActiveMQ in WebSphere to look up the
> connectionFactory by JNDI in the web application. The connectionFactory I
> get from the server is wrapped inside a SingleConnectionFactory object to
> cache the connection among all the containers.
>
> @Configuration
> @EnableJms
> public class JmsConfiguration {
>
>         @Bean
>         public ConnectionFactory connectionFactory() {
>                 JndiObjectFactoryBean jndiObjectFactoryBean = new
> JndiObjectFactoryBean();
>
> jndiObjectFactoryBean.setJndiName("jms/testConntectionFactory");
>
>                 //ActiveMq connectionFactory
>                 ConnectionFactory connectionFactory = (ConnectionFactory)
> jndiObjectFactoryBean.getObject();
>
>                 //Wrapper to cache connection
>                 return new
> SingleConnectionFactory(activeMqConnectionFactory);
>         }
> }
>
> Caching the Connection object inside the application is a good solution as
> far as there aren't too many application deployed in the server. Because,
> as
> I've understood, with this technique every application would have an opened
> connection.
>
> However, in my scenario it's pretty likely to have many applications
> deployed in the server (around 100 web applications) and every application
> listening to the broker. In this scenario, there would be one hundred JMS
> connections opened, one per application. I wonder if there is a way to
> share
> the same connection among all the applications.
>
> For example, I can configure the server's ConnectionFactory as a
> SingleConnectionFactory. In this way, when I looked up the
> ConnectionFactory
> by JNDI, I don't need to wrap it because it is SingleConnectionFactory and
> all the applications of the server share the same connection. For example:
>
> @Configuration
> @EnableJms
> public class JmsConfiguration {
>
>         @Bean
>         public ConnectionFactory connectionFactory() {
>                 JndiObjectFactoryBean jndiObjectFactoryBean = new
> JndiObjectFactoryBean();
>         jndiObjectFactoryBean.setJndiName("jms/testConntectionFactory");
>
>         //The connectioFactory I've got fron JNDI is
> SingleConnectionFactory
>                 return (ConnectionFactory)
> jndiObjectFactoryBean.getObject();
>         }
> }
>
> Is this a common configuration in production environments?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Production-ConnectionFactory-configuration-with-Spring-tp4708601.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Production ConnectionFactory configuration with Spring

Posted by itelleria <te...@gmail.com>.
>From my point of view, one difference between SingleConnectionFactory and
PooledConnectionFactory is that SingleConnectionFactory reuse the same
connection among all the listeners/consumers and PooledConnectionFactory
shares a pooled of connections among the listeners/consumers.

I think if I use DefaultMessageListenerContainers (DMLC) and a
PooledConnectionFactory together, the pool might run out of connections
because by default every DMLC keeps an opened connection. Therefore, if I
had got three DMLCs per application by average, and one hundred application
deployed in the server, I would have 300 connections opened in the server.

Here there is a similar post about this issue:
http://stackoverflow.com/a/25930513/1918308 Based on this answer, it seems
it isn't recommended to use DLMC and PooledConnectionFactory together.

Using a SingleConnectionFactory per application, there is a decrement of
number connections. Following the previous example, I would have 100
connections, one per application.

Until now, is there any mistake in my approach?

The thing is that I want to go a step further. Bearing in mind the
connection object is stateless, I am considering to reuse the same
connection among all the applications. Might there be performance problems
if all applications share the same connection?





--
View this message in context: http://activemq.2283324.n4.nabble.com/Production-ConnectionFactory-configuration-with-Spring-tp4708601p4708631.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.