Search in sources :

Example 1 with TopicConnection

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

the class SingleConnectionFactory method createTopicConnection.

@Override
public TopicConnection createTopicConnection() throws JMSException {
    Connection con;
    synchronized (this.connectionMonitor) {
        this.pubSubMode = Boolean.TRUE;
        con = createConnection();
    }
    if (!(con instanceof TopicConnection)) {
        throw new jakarta.jms.IllegalStateException("This SingleConnectionFactory does not hold a TopicConnection but rather: " + con);
    }
    return ((TopicConnection) con);
}
Also used : QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) TopicConnection(jakarta.jms.TopicConnection)

Example 2 with TopicConnection

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

the class TransactionAwareConnectionFactoryProxy method createTopicConnection.

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

Example 3 with TopicConnection

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

the class SingleConnectionFactoryTests method testWithTopicConnectionFactoryAndJms11Usage.

@Test
public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException {
    TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
    TopicConnection con = mock(TopicConnection.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 : TopicConnectionFactory(jakarta.jms.TopicConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) TopicConnection(jakarta.jms.TopicConnection) Test(org.junit.jupiter.api.Test)

Example 4 with TopicConnection

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

the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage.

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

Example 5 with TopicConnection

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

the class SingleConnectionFactoryTests method testWithTopicConnectionFactoryAndJms102Usage.

@Test
public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
    TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
    TopicConnection con = mock(TopicConnection.class);
    given(cf.createTopicConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createTopicConnection();
    Connection con2 = scf.createTopicConnection();
    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 : TopicConnectionFactory(jakarta.jms.TopicConnectionFactory) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) TopicConnection(jakarta.jms.TopicConnection) Test(org.junit.jupiter.api.Test)

Aggregations

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