Search in sources :

Example 1 with TopicConnectionFactory

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

the class TransactionAwareConnectionFactoryProxy method createTopicConnection.

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

Example 2 with TopicConnectionFactory

use of javax.jms.TopicConnectionFactory 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(javax.jms.TopicConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection) Test(org.junit.Test)

Example 3 with TopicConnectionFactory

use of javax.jms.TopicConnectionFactory 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(javax.jms.TopicConnectionFactory) TopicSession(javax.jms.TopicSession) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 4 with TopicConnectionFactory

use of javax.jms.TopicConnectionFactory in project wildfly by wildfly.

the class SimpleTimerMDBTestCase method sendMessage.

//the timer is created when the
public void sendMessage() throws Exception {
    final InitialContext ctx = new InitialContext();
    final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
    final TopicConnection connection = factory.createTopicConnection();
    connection.start();
    try {
        final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        final Message message = session.createTextMessage("Test");
        final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
    } finally {
        connection.close();
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) Destination(javax.jms.Destination) TopicSession(javax.jms.TopicSession) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) TopicConnection(javax.jms.TopicConnection) InitialContext(javax.naming.InitialContext)

Example 5 with TopicConnectionFactory

use of javax.jms.TopicConnectionFactory in project tomee by apache.

the class ContextLookupStatefulPojoBean method lookupJMSConnectionFactory.

public void lookupJMSConnectionFactory() throws TestFailureException {
    try {
        try {
            Object obj = ejbContext.lookup("jms");
            Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
            final ConnectionFactory connectionFactory = (ConnectionFactory) obj;
            testJmsConnection(connectionFactory.createConnection());
            obj = ejbContext.lookup("TopicCF");
            Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
            final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
            testJmsConnection(topicConnectionFactory.createConnection());
            obj = ejbContext.lookup("QueueCF");
            Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
            final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
            testJmsConnection(queueConnectionFactory.createConnection());
        } catch (final Exception e) {
            e.printStackTrace();
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatelessObject(org.apache.openejb.test.stateless.BasicStatelessObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) JMSException(javax.jms.JMSException) TestFailureException(org.apache.openejb.test.TestFailureException)

Aggregations

TopicConnectionFactory (javax.jms.TopicConnectionFactory)22 ConnectionFactory (javax.jms.ConnectionFactory)18 QueueConnectionFactory (javax.jms.QueueConnectionFactory)18 JMSException (javax.jms.JMSException)15 AssertionFailedError (junit.framework.AssertionFailedError)15 TestFailureException (org.apache.openejb.test.TestFailureException)15 EJBException (javax.ejb.EJBException)13 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)11 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)11 RemoteException (java.rmi.RemoteException)10 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)10 InitialContext (javax.naming.InitialContext)8 TopicConnection (javax.jms.TopicConnection)6 RemoveException (javax.ejb.RemoveException)4 CreateException (javax.ejb.CreateException)3 Connection (javax.jms.Connection)3 QueueConnection (javax.jms.QueueConnection)3 Test (org.junit.Test)3 TopicSession (javax.jms.TopicSession)2 Destination (javax.jms.Destination)1