开发者

Creating JBoss Connection Pool for JMS queue

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜