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" <[email protected]> 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.
>

Reply via email to