Search in sources :

Example 96 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class BasicOpenWireTest method createFactories.

protected void createFactories() {
    factory = new ActiveMQConnectionFactory(getConnectionUrl());
    looseFactory = new ActiveMQConnectionFactory(urlStringLoose);
    xaFactory = new ActiveMQXAConnectionFactory(getConnectionUrl());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQXAConnectionFactory(org.apache.activemq.ActiveMQXAConnectionFactory)

Example 97 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class MessageListenerRedeliveryTest method createRetryConnection.

protected Connection createRetryConnection() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlString);
    factory.setRedeliveryPolicy(getRedeliveryPolicy());
    return factory.createConnection();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 98 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class VirtualTopicToFQQNOpenWireTest method testAutoVirtualTopicFQQN.

@Test
public void testAutoVirtualTopicFQQN() throws Exception {
    Connection connection = null;
    SimpleString topic = new SimpleString("VirtualTopic.Orders");
    this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateQueues(true);
    this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setAutoCreateAddresses(true);
    try {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(urlString);
        activeMQConnectionFactory.setWatchTopicAdvisories(false);
        connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createTopic(topic.toString());
        MessageConsumer messageConsumerA = session.createConsumer(session.createQueue("Consumer.A." + topic.toString()));
        MessageConsumer messageConsumerB = session.createConsumer(session.createQueue("Consumer.B." + topic.toString()));
        MessageProducer producer = session.createProducer(destination);
        TextMessage message = session.createTextMessage("This is a text message");
        producer.send(message);
        TextMessage messageReceivedA = (TextMessage) messageConsumerA.receive(2000);
        TextMessage messageReceivedB = (TextMessage) messageConsumerB.receive(2000);
        assertTrue((messageReceivedA != null && messageReceivedB != null));
        String text = messageReceivedA.getText();
        assertEquals("This is a text message", text);
        messageConsumerA.close();
        messageConsumerB.close();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 99 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class OpenWireDivertNonExclusiveTest method testSingleNonExclusiveDivertOpenWirePublisher.

@Test
public // openwire sending, openwire receiving
void testSingleNonExclusiveDivertOpenWirePublisher() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession coreSession = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    coreSession.createQueue(new SimpleString(forwardAddress), RoutingType.ANYCAST, queueName1, null, false);
    coreSession.createQueue(new SimpleString(testAddress), RoutingType.ANYCAST, queueName2, null, false);
    coreSession.close();
    // use openwire to receive
    factory = new ActiveMQConnectionFactory(urlString);
    Connection openwireConnection = factory.createConnection();
    try {
        Session session = openwireConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        openwireConnection.start();
        MessageProducer producer = session.createProducer(session.createQueue(testAddress));
        final int numMessages = 10;
        final String propKey = "testkey";
        for (int i = 0; i < numMessages; i++) {
            Message message = session.createMessage();
            message.setIntProperty(propKey, i);
            producer.send(message);
        }
        Queue q1 = session.createQueue(CompositeAddress.toFullQN(testAddress, "queue1"));
        Queue q2 = session.createQueue(CompositeAddress.toFullQN(forwardAddress, "queue2"));
        MessageConsumer consumer1 = session.createConsumer(q1);
        MessageConsumer consumer2 = session.createConsumer(q2);
        System.out.println("receiving ...");
        for (int i = 0; i < numMessages; i++) {
            Message message = consumer1.receive(TIMEOUT);
            Assert.assertNotNull(message);
            Assert.assertEquals(i, message.getObjectProperty(propKey.toString()));
            message.acknowledge();
        }
        Assert.assertNull(consumer1.receive(50));
        for (int i = 0; i < numMessages; i++) {
            Message message = consumer2.receive(TIMEOUT);
            Assert.assertNotNull(message);
            Assert.assertEquals(i, message.getObjectProperty(propKey.toString()));
            message.acknowledge();
        }
        Assert.assertNull(consumer2.receive(50));
    } finally {
        if (openwireConnection != null) {
            openwireConnection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 100 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class VerySimpleOenwireTest method testOpenWireExample.

/**
 * This is the example shipped with the distribution
 *
 * @throws Exception
 */
@Test
public void testOpenWireExample() throws Exception {
    Connection exConn = null;
    SimpleString durableQueue = new SimpleString("exampleQueue");
    this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
    try {
        ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
        Queue queue = new ActiveMQQueue("exampleQueue");
        exConn = exFact.createConnection();
        exConn.start();
        Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("This is a text message");
        producer.send(message);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        assertEquals("This is a text message", messageReceived.getText());
    } finally {
        if (exConn != null) {
            exConn.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)436 Session (javax.jms.Session)148 Connection (javax.jms.Connection)144 Test (org.junit.Test)107 MessageConsumer (javax.jms.MessageConsumer)103 TextMessage (javax.jms.TextMessage)81 MessageProducer (javax.jms.MessageProducer)79 Message (javax.jms.Message)74 Queue (javax.jms.Queue)66 JMSException (javax.jms.JMSException)65 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)51 ConnectionFactory (javax.jms.ConnectionFactory)48 Destination (javax.jms.Destination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)36 BrokerService (org.apache.activemq.broker.BrokerService)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 Before (org.junit.Before)27 MessageListener (javax.jms.MessageListener)26 CamelContext (org.apache.camel.CamelContext)26 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23