Search in sources :

Example 1 with ConnectionResource

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;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ConnectionResource(org.apache.camel.component.sjms.jms.ConnectionResource) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 2 with ConnectionResource

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);
}
Also used : ConnectionResource(org.apache.camel.component.sjms.jms.ConnectionResource) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 3 with ConnectionResource

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);
    }
}
Also used : ConnectionResource(org.apache.camel.component.sjms.jms.ConnectionResource) Connection(javax.jms.Connection)

Aggregations

Connection (javax.jms.Connection)3 ConnectionResource (org.apache.camel.component.sjms.jms.ConnectionResource)3 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Session (javax.jms.Session)1 Test (org.junit.Test)1