use of org.apache.camel.component.sjms.jms.ConnectionResource in project camel by apache.
the class SjmsConsumer method createConsumer.
/**
* Creates a {@link MessageConsumerResources} with a dedicated
* {@link Session} required for transacted and InOut consumers.
*/
private MessageConsumerResources createConsumer() throws Exception {
MessageConsumerResources answer;
ConnectionResource connectionResource = getOrCreateConnectionResource();
Connection conn = connectionResource.borrowConnection();
try {
Session session = conn.createSession(isTransacted(), isTransacted() ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
MessageConsumer messageConsumer = getEndpoint().getJmsObjectFactory().createMessageConsumer(session, getEndpoint());
MessageListener handler = createMessageHandler(session);
messageConsumer.setMessageListener(handler);
answer = new MessageConsumerResources(session, messageConsumer);
} catch (Exception e) {
log.error("Unable to create the MessageConsumer", e);
throw e;
} finally {
connectionResource.returnConnection(conn);
}
return answer;
}
use of org.apache.camel.component.sjms.jms.ConnectionResource in project camel by apache.
the class ConnectionResourceIT method testCreateConnections.
/**
* Test method for
* {@link org.apache.commons.pool.ObjectPool#returnObject(java.lang.Object)}
* .
*
* @throws Exception
*/
@Test
public void testCreateConnections() throws Exception {
ConnectionResource pool = new AMQConnectionResource("tcp://localhost:33333", 1);
assertNotNull(pool);
Connection connection = pool.borrowConnection();
assertNotNull(connection);
assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
pool.returnConnection(connection);
Connection connection2 = pool.borrowConnection();
assertNotNull(connection2);
}
use of org.apache.camel.component.sjms.jms.ConnectionResource in project camel by apache.
the class SjmsProducer method createSession.
protected Session createSession() throws Exception {
ConnectionResource connectionResource = getOrCreateConnectionResource();
Connection conn = connectionResource.borrowConnection();
try {
return conn.createSession(isEndpointTransacted(), getAcknowledgeMode());
} catch (Exception e) {
log.error("Unable to create the Session", e);
throw e;
} finally {
connectionResource.returnConnection(conn);
}
}
Aggregations