开发者

Creating JBoss Connection Pool for JMS queue

开发者 https://www.devze.com 2023-03-19 23:48 出处:网络
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.

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(queu开发者_运维百科e);

    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


This wiki link should help: http://community.jboss.org/wiki/JBossJMSRA

=======================================================

Update: Here is the post with more information on configuration involved. I would strongly recommend to compare elapsed time for your existing approach and this one. The reason being this interesting post which suggests that JCA caching does not come into picture for remote connection factories bound to local JNDI. If that's the case, you could use the approach that Nicholas mentioned. Basically create and cache JMS connection with decent hooks in place to refresh that connection (when needed).


Technically, you only need one connection, since they are thread safe. See this How to handle a Connection object to remote jms server

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号