Search in sources :

Example 21 with ActiveMQRAManagedConnectionFactory

use of org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory in project activemq-artemis by apache.

the class OutgoingConnectionNoJTATest method testSimpleMessageSendAndReceiveSessionTransacted.

@Test
public void testSimpleMessageSendAndReceiveSessionTransacted() throws Exception {
    setupDLQ(10);
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setAllowLocalTransactions(true);
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(true, Session.SESSION_TRANSACTED);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    s.commit();
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.rollback();
    textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.commit();
    textMessage = (TextMessage) consumer.receiveNoWait();
    assertNull(textMessage);
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) QueueConnection(javax.jms.QueueConnection) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)21 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)20 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)15 Test (org.junit.Test)15 QueueConnection (javax.jms.QueueConnection)14 Session (javax.jms.Session)9 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)9 XAQueueConnection (javax.jms.XAQueueConnection)8 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)7 MessageProducer (javax.jms.MessageProducer)6 QueueSession (javax.jms.QueueSession)6 Message (javax.jms.Message)5 MessageConsumer (javax.jms.MessageConsumer)5 Queue (javax.jms.Queue)5 TextMessage (javax.jms.TextMessage)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ActiveMQRAManagedConnection (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection)5 ActiveMQRASession (org.apache.activemq.artemis.ra.ActiveMQRASession)5 Before (org.junit.Before)5 HashSet (java.util.HashSet)4