I am developing a Web Service solution that is hosted inside a JBoss 4.2.3 sever and connects to a JMS queue that is hosted on another server.
So far I am creating a new connection to the JMS queue each time the web service is called, this means that, whenever a new session is opened a new connection to the JMS queue is created.
For example, I use the code below to create the Producer:
InitialContext jmsContext;
ConnectionFactory connectionFactory;
Properties properties;
Queue queue;
properties = JMSProperties.getJNDIProperties();
jmsContext = new InitialContext(properties);
connectionFactory = (ConnectionFactory) jmsContext.lookup("ConnectionFactory");
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (Queue) jmsContext.lookup(queueName);
producer = session.createProducer(queue);
connection.start();
I am aware that this implementation is not very efficient and I am thinking about creating a connection pool so that I don't have to create a new connection everytime the web service receives a new request.
How can I configure JBoss so that it will create a connection pool to the JMS queue? Does the ConnectionFactory class automatically creates a connection pool for me? If so how can I configure the pool's size?
Thanks, Felipe