Search in sources :

Example 1 with XAQueueConnection

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

the class ConnectionFactoryTest method testConnectionTypes.

@Test
public void testConnectionTypes() throws Exception {
    deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory");
    deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE");
    deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE");
    deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC");
    deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE");
    Connection genericConnection = null;
    XAConnection xaConnection = null;
    QueueConnection queueConnection = null;
    TopicConnection topicConnection = null;
    XAQueueConnection xaQueueConnection = null;
    XATopicConnection xaTopicConnection = null;
    ConnectionFactory genericFactory = (ConnectionFactory) ic.lookup("/ConnectionFactory");
    genericConnection = genericFactory.createConnection();
    assertConnectionType(genericConnection, "generic");
    XAConnectionFactory xaFactory = (XAConnectionFactory) ic.lookup("/CF_XA_TRUE");
    xaConnection = xaFactory.createXAConnection();
    assertConnectionType(xaConnection, "xa");
    QueueConnectionFactory queueCF = (QueueConnectionFactory) ic.lookup("/CF_QUEUE");
    queueConnection = queueCF.createQueueConnection();
    assertConnectionType(queueConnection, "queue");
    TopicConnectionFactory topicCF = (TopicConnectionFactory) ic.lookup("/CF_TOPIC");
    topicConnection = topicCF.createTopicConnection();
    assertConnectionType(topicConnection, "topic");
    XAQueueConnectionFactory xaQueueCF = (XAQueueConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE");
    xaQueueConnection = xaQueueCF.createXAQueueConnection();
    assertConnectionType(xaQueueConnection, "xa-queue");
    XATopicConnectionFactory xaTopicCF = (XATopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE");
    xaTopicConnection = xaTopicCF.createXATopicConnection();
    assertConnectionType(xaTopicConnection, "xa-topic");
    genericConnection.close();
    xaConnection.close();
    queueConnection.close();
    topicConnection.close();
    xaQueueConnection.close();
    xaTopicConnection.close();
    undeployConnectionFactory("ConnectionFactory");
    undeployConnectionFactory("CF_QUEUE_XA_TRUE");
    undeployConnectionFactory("CF_XA_TRUE");
    undeployConnectionFactory("CF_QUEUE");
    undeployConnectionFactory("CF_TOPIC");
    undeployConnectionFactory("CF_TOPIC_XA_TRUE");
}
Also used : XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) XAConnection(javax.jms.XAConnection) XATopicConnection(javax.jms.XATopicConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) XAConnectionFactory(javax.jms.XAConnectionFactory) XATopicConnection(javax.jms.XATopicConnection) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) XATopicConnectionFactory(javax.jms.XATopicConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) XATopicConnection(javax.jms.XATopicConnection) TopicConnection(javax.jms.TopicConnection) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 2 with XAQueueConnection

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

the class OutgoingConnectionTest method testSimpleMessageSendAndReceiveXA.

@Test
public void testSimpleMessageSendAndReceiveXA() throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection();
    XASession s = queueConnection.createXASession();
    XAResource resource = s.getXAResource();
    resource.start(xid, XAResource.TMNOFLAGS);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receiveNoWait();
    assertNull(textMessage);
    resource.end(xid, XAResource.TMSUCCESS);
    resource.commit(xid, true);
    resource.start(xid, XAResource.TMNOFLAGS);
    textMessage = (TextMessage) consumer.receiveNoWait();
    resource.end(xid, XAResource.TMSUCCESS);
    resource.commit(xid, true);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    // When I wrote this call, this method was doing an infinite loop.
    // this is just to avoid such thing again
    textMessage.getJMSDeliveryTime();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) XASession(javax.jms.XASession) MessageProducer(javax.jms.MessageProducer) XAQueueConnection(javax.jms.XAQueueConnection) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 3 with XAQueueConnection

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

the class OutgoingConnectionTest method testOutgoingXAResourceWrapper.

@Test
public void testOutgoingXAResourceWrapper() throws Exception {
    XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection();
    XASession s = queueConnection.createXASession();
    XAResource resource = s.getXAResource();
    assertTrue(resource instanceof ActiveMQXAResourceWrapper);
    ActiveMQXAResourceWrapperImpl xaResourceWrapper = (ActiveMQXAResourceWrapperImpl) resource;
    assertTrue(xaResourceWrapper.getJndiName().equals("java://jmsXA NodeId:" + server.getNodeID()));
    assertTrue(xaResourceWrapper.getProductVersion().equals(VersionLoader.getVersion().getFullVersion()));
    assertTrue(xaResourceWrapper.getProductName().equals(ActiveMQResourceAdapter.PRODUCT_NAME));
}
Also used : XAResource(javax.transaction.xa.XAResource) ActiveMQXAResourceWrapper(org.apache.activemq.artemis.service.extensions.xa.ActiveMQXAResourceWrapper) XASession(javax.jms.XASession) XAQueueConnection(javax.jms.XAQueueConnection) ActiveMQXAResourceWrapperImpl(org.apache.activemq.artemis.service.extensions.xa.ActiveMQXAResourceWrapperImpl) Test(org.junit.Test)

Example 4 with XAQueueConnection

use of javax.jms.XAQueueConnection in project ofbiz-framework by apache.

the class JmsServiceEngine method runXaQueue.

protected Map<String, Object> runXaQueue(ModelService modelService, Map<String, Object> context, Element server) throws GenericServiceException {
    String serverName = server.getAttribute("jndi-server-name");
    String jndiName = server.getAttribute("jndi-name");
    String queueName = server.getAttribute("topic-queue");
    String userName = server.getAttribute("username");
    String password = server.getAttribute("password");
    String clientId = server.getAttribute("client-id");
    InitialContext jndi = null;
    XAQueueConnectionFactory factory = null;
    XAQueueConnection con = null;
    try {
        jndi = JNDIContextFactory.getInitialContext(serverName);
        factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
    } catch (GeneralException ge) {
        throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
    } catch (NamingException ne) {
        JNDIContextFactory.clearInitialContext(serverName);
        try {
            jndi = JNDIContextFactory.getInitialContext(serverName);
            factory = (XAQueueConnectionFactory) jndi.lookup(jndiName);
        } catch (GeneralException ge2) {
            throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
        } catch (NamingException ne2) {
            throw new GenericServiceException("JNDI lookup problems.", ne2);
        }
    }
    try {
        con = factory.createXAQueueConnection(userName, password);
        if (clientId.length() > 1)
            con.setClientID(userName);
        con.start();
        // enlist the XAResource
        XAQueueSession session = con.createXAQueueSession();
        XAResource resource = session.getXAResource();
        if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE)
            TransactionUtil.enlistResource(resource);
        Queue queue = (Queue) jndi.lookup(queueName);
        QueueSession qSession = session.getQueueSession();
        QueueSender sender = qSession.createSender(queue);
        // create/send the message
        Message message = makeMessage(session, modelService, context);
        sender.send(message);
        if (TransactionUtil.getStatus() != TransactionUtil.STATUS_ACTIVE)
            session.commit();
        Debug.logInfo("Message sent.", module);
        // close the connections
        sender.close();
        session.close();
        con.close();
    } catch (GenericTransactionException gte) {
        throw new GenericServiceException("Problems enlisting resource w/ transaction manager.", gte.getNested());
    } catch (NamingException ne) {
        throw new GenericServiceException("Problems with JNDI lookup.", ne);
    } catch (JMSException je) {
        throw new GenericServiceException("JMS Internal Error.", je);
    }
    return ServiceUtil.returnSuccess();
}
Also used : GeneralException(org.apache.ofbiz.base.util.GeneralException) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) XAQueueConnection(javax.jms.XAQueueConnection) InitialContext(javax.naming.InitialContext) XAResource(javax.transaction.xa.XAResource) XAQueueSession(javax.jms.XAQueueSession) QueueSender(javax.jms.QueueSender) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) XAQueueConnectionFactory(javax.jms.XAQueueConnectionFactory) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) NamingException(javax.naming.NamingException) Queue(javax.jms.Queue) XAQueueSession(javax.jms.XAQueueSession) QueueSession(javax.jms.QueueSession)

Example 5 with XAQueueConnection

use of javax.jms.XAQueueConnection in project brave by openzipkin.

the class JmsTracingTest method xaQueueConnection_doesntDoubleWrap.

@Test
public void xaQueueConnection_doesntDoubleWrap() {
    XAQueueConnection wrapped = jmsTracing.xaQueueConnection(mock(XAQueueConnection.class));
    assertThat(jmsTracing.xaQueueConnection(wrapped)).isSameAs(wrapped);
}
Also used : XAQueueConnection(javax.jms.XAQueueConnection) Test(org.junit.Test)

Aggregations

XAQueueConnection (javax.jms.XAQueueConnection)5 Test (org.junit.Test)4 XAResource (javax.transaction.xa.XAResource)3 Message (javax.jms.Message)2 Queue (javax.jms.Queue)2 XAQueueConnectionFactory (javax.jms.XAQueueConnectionFactory)2 XASession (javax.jms.XASession)2 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 QueueConnection (javax.jms.QueueConnection)1 QueueConnectionFactory (javax.jms.QueueConnectionFactory)1 QueueSender (javax.jms.QueueSender)1 QueueSession (javax.jms.QueueSession)1 TextMessage (javax.jms.TextMessage)1 TopicConnection (javax.jms.TopicConnection)1 TopicConnectionFactory (javax.jms.TopicConnectionFactory)1