Search in sources :

Example 56 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue 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 57 with ActiveMQQueue

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

the class SimpleOpenWireTest method testSendEmptyMessages.

@Test
public void testSendEmptyMessages() throws Exception {
    Queue dest = new ActiveMQQueue(queueName);
    QueueSession defaultQueueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueSender defaultSender = defaultQueueSession.createSender(dest);
    defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    connection.start();
    Message msg = defaultQueueSession.createMessage();
    msg.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(msg);
    QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
    // bytes
    BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
    bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(bytesMessage);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
    // map
    MapMessage mapMessage = defaultQueueSession.createMapMessage();
    mapMessage.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(mapMessage);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
    // object
    ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
    objMessage.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(objMessage);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
    // stream
    StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
    streamMessage.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(streamMessage);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
    // text
    TextMessage textMessage = defaultQueueSession.createTextMessage();
    textMessage.setStringProperty("testName", "testSendEmptyMessages");
    defaultSender.send(textMessage);
    assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}
Also used : MapMessage(javax.jms.MapMessage) StreamMessage(javax.jms.StreamMessage) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) ObjectMessage(javax.jms.ObjectMessage) MapMessage(javax.jms.MapMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) BytesMessage(javax.jms.BytesMessage) StreamMessage(javax.jms.StreamMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 58 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue 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 59 with ActiveMQQueue

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

the class SimpleOpenWireTest method testAutoDestinationCreationOnProducerSend.

@Test
public void testAutoDestinationCreationOnProducerSend() throws JMSException {
    AddressSettings addressSetting = new AddressSettings();
    addressSetting.setAutoCreateQueues(true);
    addressSetting.setAutoCreateAddresses(true);
    String address = "foo";
    server.getAddressSettingsRepository().addMatch(address, addressSetting);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TextMessage message = session.createTextMessage("bar");
    Queue queue = new ActiveMQQueue(address);
    MessageProducer producer = session.createProducer(null);
    producer.send(queue, message);
    MessageConsumer consumer = session.createConsumer(queue);
    TextMessage message1 = (TextMessage) consumer.receive(1000);
    assertTrue(message1.getText().equals(message.getText()));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageConsumer(javax.jms.MessageConsumer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 60 with ActiveMQQueue

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

the class RedeliveryPolicyTest method testNornalRedeliveryPolicyDelaysDeliveryOnRollback.

/**
 * @throws Exception
 */
@Test
public void testNornalRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(0);
    policy.setRedeliveryDelay(500);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
    this.makeSureCoreQueueExist("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    producer.send(session.createTextMessage("1st"));
    producer.send(session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) consumer.receive(1000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    // No delay on first rollback..
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    session.rollback();
    // Show subsequent re-delivery delay is incrementing.
    m = (TextMessage) consumer.receive(100);
    assertNull(m);
    m = (TextMessage) consumer.receive(700);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    // The message gets redelivered after 500 ms every time since
    // we are not using exponential backoff.
    m = (TextMessage) consumer.receive(100);
    assertNull(m);
    m = (TextMessage) consumer.receive(700);
    assertNotNull(m);
    assertEquals("1st", m.getText());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) 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