Search in sources :

Example 6 with XAConnectionFactory

use of javax.jms.XAConnectionFactory in project narayana by jbosstm.

the class StompConnect method assignProtocolConverter.

public void assignProtocolConverter(TcpTransport transport) throws NamingException {
    ConnectionFactory factory = getConnectionFactory();
    if (factory == null) {
        throw new IllegalArgumentException("No ConnectionFactory is configured!");
    }
    XAConnectionFactory xaFactory = getXAConnectionFactory();
    if (xaFactory == null) {
        throw new IllegalArgumentException("No XAConnectionFactory is configured!");
    }
    new ProtocolConverter(initialContext, factory, xaFactory, transport);
}
Also used : XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory)

Example 7 with XAConnectionFactory

use of javax.jms.XAConnectionFactory in project narayana by jbosstm.

the class AbstractIntegrationTests method initJms.

protected void initJms() throws Exception {
    jmsServer = JMS_HELPER.startServer();
    queue = (Queue) jmsServer.lookup(JmsHelper.QUEUE_NAME);
    ConnectionFactory connectionFactory = new ConnectionFactoryProxy((XAConnectionFactory) jmsServer.lookup(JmsHelper.FACTORY_NAME), new TransactionHelperImpl(TransactionManager.transactionManager()));
    connection = connectionFactory.createConnection();
    connection.start();
}
Also used : ConnectionFactoryProxy(org.jboss.narayana.jta.jms.ConnectionFactoryProxy) XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) TransactionHelperImpl(org.jboss.narayana.jta.jms.TransactionHelperImpl)

Example 8 with XAConnectionFactory

use of javax.jms.XAConnectionFactory in project spring-boot by spring-projects.

the class AtomikosXAConnectionFactoryWrapperTests method wrap.

@Test
public void wrap() {
    XAConnectionFactory connectionFactory = mock(XAConnectionFactory.class);
    AtomikosXAConnectionFactoryWrapper wrapper = new AtomikosXAConnectionFactoryWrapper();
    ConnectionFactory wrapped = wrapper.wrapConnectionFactory(connectionFactory);
    assertThat(wrapped).isInstanceOf(AtomikosConnectionFactoryBean.class);
    assertThat(((AtomikosConnectionFactoryBean) wrapped).getXaConnectionFactory()).isSameAs(connectionFactory);
}
Also used : XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) Test(org.junit.Test)

Example 9 with XAConnectionFactory

use of javax.jms.XAConnectionFactory in project spring-boot by spring-projects.

the class BitronixXAConnectionFactoryWrapperTests method wrap.

@Test
public void wrap() {
    XAConnectionFactory connectionFactory = mock(XAConnectionFactory.class);
    BitronixXAConnectionFactoryWrapper wrapper = new BitronixXAConnectionFactoryWrapper();
    ConnectionFactory wrapped = wrapper.wrapConnectionFactory(connectionFactory);
    assertThat(wrapped).isInstanceOf(PoolingConnectionFactoryBean.class);
    assertThat(((PoolingConnectionFactoryBean) wrapped).getConnectionFactory()).isSameAs(connectionFactory);
}
Also used : XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) Test(org.junit.Test)

Example 10 with XAConnectionFactory

use of javax.jms.XAConnectionFactory in project activemq-artemis by apache.

the class SimpleMessageListener method main.

public static void main(final String[] args) throws Exception {
    AtomicBoolean result = new AtomicBoolean(true);
    final ArrayList<String> receiveHolder = new ArrayList<>();
    XAConnection connection = null;
    InitialContext initialContext = null;
    try {
        // Step 1. Create an initial context to perform the JNDI lookup.
        initialContext = new InitialContext();
        // Step 2. Lookup on the queue
        Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
        // Step 3. Perform a lookup on the XA Connection Factory
        XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("XAConnectionFactory");
        // Step 4.Create a JMS XAConnection
        connection = cf.createXAConnection();
        // Step 5. Start the connection
        connection.start();
        // Step 6. Create a JMS XASession
        XASession xaSession = connection.createXASession();
        // Step 7. Create a normal session
        Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 8. Create a normal Message Consumer
        MessageConsumer normalConsumer = normalSession.createConsumer(queue);
        normalConsumer.setMessageListener(new SimpleMessageListener(receiveHolder, result));
        // Step 9. Get the JMS Session
        Session session = xaSession.getSession();
        // Step 10. Create a message producer
        MessageProducer producer = session.createProducer(queue);
        // Step 11. Create two Text Messages
        TextMessage helloMessage = session.createTextMessage("hello");
        TextMessage worldMessage = session.createTextMessage("world");
        // Step 12. create a transaction
        Xid xid1 = new DummyXid("xa-example1".getBytes(StandardCharsets.UTF_8), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
        // Step 13. Get the JMS XAResource
        XAResource xaRes = xaSession.getXAResource();
        // Step 14. Begin the Transaction work
        xaRes.start(xid1, XAResource.TMNOFLAGS);
        // Step 15. do work, sending two messages.
        producer.send(helloMessage);
        producer.send(worldMessage);
        Thread.sleep(2000);
        // Step 16. Check the result, it should receive none!
        checkNoMessageReceived(receiveHolder);
        // Step 17. Stop the work
        xaRes.end(xid1, XAResource.TMSUCCESS);
        // Step 18. Prepare
        xaRes.prepare(xid1);
        // Step 19. Roll back the transaction
        xaRes.rollback(xid1);
        // Step 20. No messages should be received!
        checkNoMessageReceived(receiveHolder);
        // Step 21. Create another transaction
        Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
        // Step 22. Start the transaction
        xaRes.start(xid2, XAResource.TMNOFLAGS);
        // Step 23. Re-send those messages
        producer.send(helloMessage);
        producer.send(worldMessage);
        // Step 24. Stop the work
        xaRes.end(xid2, XAResource.TMSUCCESS);
        // Step 25. Prepare
        xaRes.prepare(xid2);
        // Step 26. No messages should be received at this moment
        checkNoMessageReceived(receiveHolder);
        // Step 27. Commit!
        xaRes.commit(xid2, false);
        Thread.sleep(2000);
        // Step 28. Check the result, all message received
        checkAllMessageReceived(receiveHolder);
        if (!result.get())
            throw new IllegalStateException();
    } finally {
        // Step 29. Be sure to close our JMS resources!
        if (initialContext != null) {
            initialContext.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ArrayList(java.util.ArrayList) InitialContext(javax.naming.InitialContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XASession(javax.jms.XASession) XAConnectionFactory(javax.jms.XAConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) XAConnection(javax.jms.XAConnection) XASession(javax.jms.XASession) Session(javax.jms.Session)

Aggregations

XAConnectionFactory (javax.jms.XAConnectionFactory)14 ConnectionFactory (javax.jms.ConnectionFactory)7 Test (org.junit.Test)6 XAConnection (javax.jms.XAConnection)5 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)5 InitialContext (javax.naming.InitialContext)4 Connection (javax.jms.Connection)3 MessageConsumer (javax.jms.MessageConsumer)3 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 Session (javax.jms.Session)3 TextMessage (javax.jms.TextMessage)3 XASession (javax.jms.XASession)3 ConnectionFactoryProxy (org.jboss.narayana.jta.jms.ConnectionFactoryProxy)3 TransactionHelperImpl (org.jboss.narayana.jta.jms.TransactionHelperImpl)3 QueueConnectionFactory (javax.jms.QueueConnectionFactory)2 TopicConnectionFactory (javax.jms.TopicConnectionFactory)2 XAQueueConnectionFactory (javax.jms.XAQueueConnectionFactory)2 XATopicConnectionFactory (javax.jms.XATopicConnectionFactory)2 XAResource (javax.transaction.xa.XAResource)2