Search in sources :

Example 1 with QueueConnectionFactory

use of jakarta.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class TransactionAwareConnectionFactoryProxy method createQueueConnection.

@Override
public QueueConnection createQueueConnection() throws JMSException {
    ConnectionFactory target = getTargetConnectionFactory();
    if (!(target instanceof QueueConnectionFactory)) {
        throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
    }
    QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection();
    return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
Also used : TopicConnectionFactory(jakarta.jms.TopicConnectionFactory) ConnectionFactory(jakarta.jms.ConnectionFactory) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory)

Example 2 with QueueConnectionFactory

use of jakarta.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage.

@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    QueueSession txSession = mock(QueueSession.class);
    QueueSession nonTxSession = mock(QueueSession.class);
    given(cf.createQueueConnection()).willReturn(con);
    given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
    given(txSession.getTransacted()).willReturn(true);
    given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
    CachingConnectionFactory scf = new CachingConnectionFactory(cf);
    scf.setReconnectOnException(false);
    Connection con1 = scf.createQueueConnection();
    Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session1.rollback();
    session1.close();
    session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session1.close();
    con1.start();
    QueueConnection con2 = scf.createQueueConnection();
    Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
    session2.close();
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session2.getTransacted();
    // should lead to rollback
    session2.close();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(txSession).rollback();
    verify(txSession).close();
    verify(nonTxSession).close();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
}
Also used : QueueConnection(jakarta.jms.QueueConnection) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) QueueSession(jakarta.jms.QueueSession) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) TopicSession(jakarta.jms.TopicSession) Test(org.junit.jupiter.api.Test)

Example 3 with QueueConnectionFactory

use of jakarta.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithQueueConnectionFactoryAndJms11Usage.

@Test
public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    given(cf.createConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createConnection();
    Connection con2 = scf.createConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnection(jakarta.jms.QueueConnection) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) Test(org.junit.jupiter.api.Test)

Example 4 with QueueConnectionFactory

use of jakarta.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithQueueConnectionFactoryAndJms102Usage.

@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    given(cf.createQueueConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createQueueConnection();
    Connection con2 = scf.createQueueConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnection(jakarta.jms.QueueConnection) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) Test(org.junit.jupiter.api.Test)

Example 5 with QueueConnectionFactory

use of jakarta.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class TransactionAwareConnectionFactoryProxy method createQueueConnection.

@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
    ConnectionFactory target = getTargetConnectionFactory();
    if (!(target instanceof QueueConnectionFactory)) {
        throw new jakarta.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
    }
    QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection(username, password);
    return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
Also used : TopicConnectionFactory(jakarta.jms.TopicConnectionFactory) ConnectionFactory(jakarta.jms.ConnectionFactory) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) QueueConnectionFactory(jakarta.jms.QueueConnectionFactory)

Aggregations

QueueConnection (jakarta.jms.QueueConnection)5 QueueConnectionFactory (jakarta.jms.QueueConnectionFactory)5 Connection (jakarta.jms.Connection)3 TopicConnection (jakarta.jms.TopicConnection)3 Test (org.junit.jupiter.api.Test)3 ConnectionFactory (jakarta.jms.ConnectionFactory)2 TopicConnectionFactory (jakarta.jms.TopicConnectionFactory)2 QueueSession (jakarta.jms.QueueSession)1 Session (jakarta.jms.Session)1 TopicSession (jakarta.jms.TopicSession)1