Search in sources :

Example 96 with Connection

use of javax.jms.Connection in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithQueueConnection.

@Test
public void testWithQueueConnection() throws JMSException {
    Connection con = mock(QueueConnection.class);
    SingleConnectionFactory scf = new SingleConnectionFactory(con);
    QueueConnection con1 = scf.createQueueConnection();
    con1.start();
    con1.stop();
    con1.close();
    QueueConnection con2 = scf.createQueueConnection();
    con2.start();
    con2.stop();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con, times(2)).start();
    verify(con, times(2)).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnection(javax.jms.QueueConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) Test(org.junit.Test)

Example 97 with Connection

use of javax.jms.Connection in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithConnectionFactoryAndClientId.

@Test
public void testWithConnectionFactoryAndClientId() throws JMSException {
    ConnectionFactory cf = mock(ConnectionFactory.class);
    Connection con = mock(Connection.class);
    given(cf.createConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    scf.setClientId("myId");
    Connection con1 = scf.createConnection();
    Connection con2 = scf.createConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).setClientID("myId");
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) Test(org.junit.Test)

Example 98 with Connection

use of javax.jms.Connection in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithTopicConnection.

@Test
public void testWithTopicConnection() throws JMSException {
    Connection con = mock(TopicConnection.class);
    SingleConnectionFactory scf = new SingleConnectionFactory(con);
    TopicConnection con1 = scf.createTopicConnection();
    con1.start();
    con1.stop();
    con1.close();
    TopicConnection con2 = scf.createTopicConnection();
    con2.start();
    con2.stop();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con, times(2)).start();
    verify(con, times(2)).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection) Test(org.junit.Test)

Example 99 with Connection

use of javax.jms.Connection in project spring-framework by spring-projects.

the class JmsInvokerClientInterceptor method executeRequest.

/**
	 * Execute the given remote invocation, sending an invoker request message
	 * to this accessor's target queue and waiting for a corresponding response.
	 * @param invocation the RemoteInvocation to execute
	 * @return the RemoteInvocationResult object
	 * @throws JMSException in case of JMS failure
	 * @see #doExecuteRequest
	 */
protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException {
    Connection con = createConnection();
    Session session = null;
    try {
        session = createSession(con);
        Queue queueToUse = resolveQueue(session);
        Message requestMessage = createRequestMessage(session, invocation);
        con.start();
        Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage);
        if (responseMessage != null) {
            return extractInvocationResult(responseMessage);
        } else {
            return onReceiveTimeout(invocation);
        }
    } finally {
        JmsUtils.closeSession(session);
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true);
    }
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session)

Example 100 with Connection

use of javax.jms.Connection in project spring-framework by spring-projects.

the class JmsResourceHolder method closeAll.

public void closeAll() {
    for (Session session : this.sessions) {
        try {
            session.close();
        } catch (Throwable ex) {
            logger.debug("Could not close synchronized JMS Session after transaction", ex);
        }
    }
    for (Connection con : this.connections) {
        ConnectionFactoryUtils.releaseConnection(con, this.connectionFactory, true);
    }
    this.connections.clear();
    this.sessions.clear();
    this.sessionsPerConnection.clear();
}
Also used : Connection(javax.jms.Connection) Session(javax.jms.Session)

Aggregations

Connection (javax.jms.Connection)124 Session (javax.jms.Session)88 Test (org.junit.Test)62 MessageProducer (javax.jms.MessageProducer)46 ConnectionFactory (javax.jms.ConnectionFactory)44 Message (javax.jms.Message)38 MessageConsumer (javax.jms.MessageConsumer)38 JMSException (javax.jms.JMSException)32 TextMessage (javax.jms.TextMessage)32 QueueConnection (javax.jms.QueueConnection)22 TopicConnection (javax.jms.TopicConnection)22 Destination (javax.jms.Destination)15 Queue (javax.jms.Queue)12 QueueConnectionFactory (javax.jms.QueueConnectionFactory)11 TopicConnectionFactory (javax.jms.TopicConnectionFactory)11 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)7 JmsTemplate (org.springframework.jms.core.JmsTemplate)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)7 TransactionAttribute (javax.ejb.TransactionAttribute)4