Search in sources :

Example 46 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ActiveMQXAConnectionFactoryTest method testCloseSendConnection.

public void testCloseSendConnection() throws Exception {
    String brokerName = "closeSend";
    BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
    broker.start();
    broker.waitUntilStarted();
    ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
    XAConnection connection = (XAConnection) cf.createConnection();
    connection.start();
    XASession session = connection.createXASession();
    XAResource resource = session.getXAResource();
    Destination dest = new ActiveMQQueue(getName());
    // publish a message
    Xid tid = createXid();
    resource.start(tid, XAResource.TMNOFLAGS);
    MessageProducer producer = session.createProducer(dest);
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setText(getName());
    producer.send(message);
    connection.close();
    // comment out this check as it doesn't apply to artemis
    // assertTransactionGoneFromBroker(tid);
    broker.stop();
}
Also used : Destination(javax.jms.Destination) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) XASession(javax.jms.XASession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) XAConnection(javax.jms.XAConnection) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 47 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ActiveMQXAConnectionFactoryTest method testSessionCloseTransactionalSendReceive.

public void testSessionCloseTransactionalSendReceive() throws Exception {
    ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
    XAConnection connection1 = (XAConnection) cf1.createConnection();
    connection1.start();
    XASession session = connection1.createXASession();
    XAResource resource = session.getXAResource();
    Destination dest = new ActiveMQQueue(getName());
    // publish a message
    Xid tid = createXid();
    resource.start(tid, XAResource.TMNOFLAGS);
    MessageProducer producer = session.createProducer(dest);
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setText(getName());
    producer.send(message);
    session.close();
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
    session = connection1.createXASession();
    MessageConsumer consumer = session.createConsumer(dest);
    tid = createXid();
    resource = session.getXAResource();
    resource.start(tid, XAResource.TMNOFLAGS);
    TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
    session.close();
    assertNotNull(receivedMessage);
    assertEquals(getName(), receivedMessage.getText());
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
    session = connection1.createXASession();
    consumer = session.createConsumer(dest);
    tid = createXid();
    resource = session.getXAResource();
    resource.start(tid, XAResource.TMNOFLAGS);
    assertNull(consumer.receive(1000));
    resource.end(tid, XAResource.TMSUCCESS);
    resource.commit(tid, true);
}
Also used : Destination(javax.jms.Destination) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) MessageConsumer(javax.jms.MessageConsumer) XASession(javax.jms.XASession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) XAConnection(javax.jms.XAConnection) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 48 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ActiveMQXAConnectionFactoryTest method testVanilaTransactionalProduceReceive.

public void testVanilaTransactionalProduceReceive() throws Exception {
    XAConnection connection1 = null;
    try {
        ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
        connection1 = (XAConnection) cf1.createConnection();
        connection1.start();
        XASession session = connection1.createXASession();
        XAResource resource = session.getXAResource();
        Destination dest = new ActiveMQQueue(getName());
        // publish a message
        Xid tid = createXid();
        resource.start(tid, XAResource.TMNOFLAGS);
        MessageProducer producer = session.createProducer(dest);
        ActiveMQTextMessage message = new ActiveMQTextMessage();
        message.setText(getName());
        producer.send(message);
        resource.end(tid, XAResource.TMSUCCESS);
        resource.commit(tid, true);
        session.close();
        session = connection1.createXASession();
        MessageConsumer consumer = session.createConsumer(dest);
        tid = createXid();
        resource = session.getXAResource();
        resource.start(tid, XAResource.TMNOFLAGS);
        TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
        assertNotNull(receivedMessage);
        assertEquals(getName(), receivedMessage.getText());
        resource.end(tid, XAResource.TMSUCCESS);
        resource.commit(tid, true);
        session.close();
    } finally {
        if (connection1 != null) {
            try {
                connection1.close();
            } catch (Exception e) {
            // ignore
            }
        }
    }
}
Also used : Destination(javax.jms.Destination) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) MessageConsumer(javax.jms.MessageConsumer) XASession(javax.jms.XASession) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) XAException(javax.transaction.xa.XAException) XAConnection(javax.jms.XAConnection) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 49 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class NetworkConnectionsTest method testNetworkConnectionReAddURI.

@Test
public void testNetworkConnectionReAddURI() throws Exception {
    LOG.info("testNetworkConnectionReAddURI is starting...");
    LOG.info("Adding network connector 'NC1'...");
    NetworkConnector nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
    nc.setName("NC1");
    nc.start();
    assertTrue(nc.isStarted());
    LOG.info("Looking up network connector by name...");
    NetworkConnector nc1 = localBroker.getNetworkConnectorByName("NC1");
    assertNotNull("Should find network connector 'NC1'", nc1);
    assertTrue(nc1.isStarted());
    assertEquals(nc, nc1);
    LOG.info("Setting up producer and consumer...");
    ActiveMQQueue destination = new ActiveMQQueue(DESTINATION_NAME);
    ActiveMQConnectionFactory localFactory = new ActiveMQConnectionFactory(LOCAL_BROKER_TRANSPORT_URI);
    Connection localConnection = localFactory.createConnection();
    localConnection.start();
    Session localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer localProducer = localSession.createProducer(destination);
    ActiveMQConnectionFactory remoteFactory = new ActiveMQConnectionFactory(REMOTE_BROKER_TRANSPORT_URI);
    Connection remoteConnection = remoteFactory.createConnection();
    remoteConnection.start();
    Session remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer remoteConsumer = remoteSession.createConsumer(destination);
    Message message = localSession.createTextMessage("test");
    localProducer.send(message);
    LOG.info("Testing initial network connection...");
    message = remoteConsumer.receive(10000);
    assertNotNull(message);
    LOG.info("Stopping network connector 'NC1'...");
    nc.stop();
    assertFalse(nc.isStarted());
    LOG.info("Removing network connector...");
    assertTrue(localBroker.removeNetworkConnector(nc));
    nc1 = localBroker.getNetworkConnectorByName("NC1");
    assertNull("Should not find network connector 'NC1'", nc1);
    LOG.info("Re-adding network connector 'NC2'...");
    nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
    nc.setName("NC2");
    nc.start();
    assertTrue(nc.isStarted());
    LOG.info("Looking up network connector by name...");
    NetworkConnector nc2 = localBroker.getNetworkConnectorByName("NC2");
    assertNotNull(nc2);
    assertTrue(nc2.isStarted());
    assertEquals(nc, nc2);
    LOG.info("Testing re-added network connection...");
    message = localSession.createTextMessage("test");
    localProducer.send(message);
    message = remoteConsumer.receive(10000);
    assertNotNull(message);
    LOG.info("Stopping network connector...");
    nc.stop();
    assertFalse(nc.isStarted());
    LOG.info("Removing network connection 'NC2'");
    assertTrue(localBroker.removeNetworkConnector(nc));
    nc2 = localBroker.getNetworkConnectorByName("NC2");
    assertNull("Should not find network connector 'NC2'", nc2);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) Test(org.junit.Test)

Example 50 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ConfigUsingDestinationOptionsTest method testValidSelectorConfig.

@Test(timeout = 60000)
public void testValidSelectorConfig() throws JMSException {
    ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test=1");
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQMessageConsumer cons;
    // JMS selector should be priority
    cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test=2");
    assertEquals("test=2", cons.getMessageSelector());
    // Test setting using JMS destinations
    cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
    assertEquals("test=1", cons.getMessageSelector());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)239 Session (javax.jms.Session)81 MessageProducer (javax.jms.MessageProducer)78 MessageConsumer (javax.jms.MessageConsumer)76 TextMessage (javax.jms.TextMessage)73 Test (org.junit.Test)66 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)54 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 Message (javax.jms.Message)36 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)33 Connection (javax.jms.Connection)32 Destination (javax.jms.Destination)27 CountDownLatch (java.util.concurrent.CountDownLatch)20 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)18 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 Message (org.apache.activemq.command.Message)17 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)16