Search in sources :

Example 91 with ActiveMQConnectionFactory

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

the class SimpleOpenWireTest method testMixedOpenWireExample.

@Test
public void testMixedOpenWireExample() throws Exception {
    Connection openConn = null;
    SimpleString durableQueue = new SimpleString("exampleQueue");
    this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
    ActiveMQConnectionFactory openCF = new ActiveMQConnectionFactory();
    Queue queue = new ActiveMQQueue("exampleQueue");
    openConn = openCF.createConnection();
    openConn.start();
    Session openSession = openConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = openSession.createProducer(queue);
    TextMessage message = openSession.createTextMessage("This is a text message");
    producer.send(message);
    org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory artemisCF = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory();
    Connection artemisConn = artemisCF.createConnection();
    Session artemisSession = artemisConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    artemisConn.start();
    MessageConsumer messageConsumer = artemisSession.createConsumer(artemisSession.createQueue("exampleQueue"));
    TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
    assertEquals("This is a text message", messageReceived.getText());
    openConn.close();
    artemisConn.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) XAConnection(javax.jms.XAConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 92 with ActiveMQConnectionFactory

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

the class SimpleOpenWireTest 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(durableQueueName);
        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) XAConnection(javax.jms.XAConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 93 with ActiveMQConnectionFactory

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

the class SimpleOpenWireTest method testMixedOpenWireExample2.

// simple test sending openwire, consuming core
@Test
public void testMixedOpenWireExample2() throws Exception {
    Connection conn1 = null;
    SimpleString durableQueue = new SimpleString("exampleQueue");
    this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
    Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
    org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory artemisCF = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory();
    conn1 = artemisCF.createConnection();
    conn1.start();
    Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session1.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        TextMessage message = session1.createTextMessage("This is a text message");
        producer.send(message);
    }
    ActiveMQConnectionFactory openCF = new ActiveMQConnectionFactory();
    Connection conn2 = openCF.createConnection();
    Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn2.start();
    MessageConsumer messageConsumer = sess2.createConsumer(sess2.createQueue("exampleQueue"));
    for (int i = 0; i < 10; i++) {
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
        assertEquals("This is a text message", messageReceived.getText());
    }
    conn1.close();
    conn2.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) XAConnection(javax.jms.XAConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 94 with ActiveMQConnectionFactory

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

the class OpenWireJMSClusteredTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    setupServer(0, true, true);
    setupServer(1, true, true);
    setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, true, 0, 1);
    setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, true, 1, 0);
    startServers(0, 1);
    waitForTopology(servers[0], 2);
    waitForTopology(servers[1], 2);
    setupSessionFactory(0, true);
    setupSessionFactory(1, true);
    String uri1 = getServerUri(0);
    String uri2 = getServerUri(1);
    openWireCf1 = new ActiveMQConnectionFactory(uri1);
    openWireCf2 = new ActiveMQConnectionFactory(uri2);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Before(org.junit.Before)

Example 95 with ActiveMQConnectionFactory

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

the class ProducerFlowControlSendFailTest method testPublishWithTX.

@Test
public void testPublishWithTX() throws Exception {
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) getConnectionFactory();
    // with sendFail, there must be no flowControllwindow
    // sendFail is an alternative flow control mechanism that does not block
    factory.setUseAsyncSend(true);
    this.flowControlConnection = (ActiveMQConnection) factory.createConnection();
    this.flowControlConnection.start();
    final Session session = this.flowControlConnection.createSession(true, Session.SESSION_TRANSACTED);
    final MessageProducer producer = session.createProducer(queueA);
    int successSent = 0;
    boolean exception = false;
    try {
        for (int i = 0; i < 5000; i++) {
            producer.send(session.createTextMessage("Test message"));
            session.commit();
            successSent++;
        }
    } catch (Exception e) {
        exception = true;
        // with async send, there will be no exceptions
        e.printStackTrace();
    }
    Assert.assertTrue(exception);
    // resourceException on second message, resumption if we
    // can receive 10
    MessageConsumer consumer = session.createConsumer(queueA);
    TextMessage msg;
    for (int idx = 0; idx < successSent; ++idx) {
        msg = (TextMessage) consumer.receive(1000);
        Assert.assertNotNull(msg);
        System.out.println("Received " + msg);
        if (msg != null) {
            msg.acknowledge();
        }
        session.commit();
    }
    consumer.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) MessageProducer(javax.jms.MessageProducer) ResourceAllocationException(javax.jms.ResourceAllocationException) JMSException(javax.jms.JMSException) 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