[prev in list] [next in list] [prev in thread] [next in thread] 

List:       activemq-users
Subject:    Production ConnectionFactory configuration with Spring
From:       itelleria <telleria () gmail ! com>
Date:       2016-02-29 22:10:01
Message-ID: 1456783801814-4708601.post () n4 ! nabble ! com
[Download RAW message or body]

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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic