3
votes

Can you, please, give me a help on one simple problem. I need to use PooledConnectionFactory without spring, JMSTemplate. ActiveMQ says that this class is pooling connections, producers, sessions, and what is confusing me, I don't know how to get them from instance. I was waiting for some takeConnection(), and then realeaseConnection() and takeProducer() and realize producer(). What should I do after pooledConnectionFactory.start(); Normaly, I would do Connection c = pooledConnectionFactory.createConnection... Hope, I explained my problem. And how producers and sessions are pooled, if they are created directly from Connection.

    connectionFactory = new ActiveMQConnectionFactory(
            userId, 
            passWord, 
            brokerURL);
    log.info("Queueing service init: BrokerURL: " + brokerURL + "  UserId: " + userId + "   Paasword: " + passWord);

    pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);

    pooledConnectionFactory.setIdleTimeout(5000);
    pooledConnectionFactory.setMaxConnections(10);
    pooledConnectionFactory.setMaximumActive(5000);
    pooledConnectionFactory.start();
1

1 Answers

3
votes

Well, the pooled connection factory is just as any other jms connection factory when it comes to using it.

Just call:

pooledConnectionFactory.createConnection(); // as you would

The connection factory will not really create connections but give you a pooled one. Then, connection.close(); will release it to the pool again. But all that is under the hood, just use it as you are used to and it will be just fine. The same goes for sessions and producers, but not consumers.