Search in sources :

Example 26 with ActiveMQDestination

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

the class BrokerTest method testQueueOnlyOnceDeliveryWith2Consumers.

public void testQueueOnlyOnceDeliveryWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        assertNotNull("m2 is null for index: " + i, m2);
        assertNotSame(m1.getMessageId(), m2.getMessageId());
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 27 with ActiveMQDestination

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

the class MessageListenerRedeliveryTest method testQueueSessionListenerExceptionDlq.

public void testQueueSessionListenerExceptionDlq() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("queue-" + getName());
    MessageProducer producer = createProducer(session, queue);
    Message message = createTextMessage(session);
    producer.send(message);
    final Message[] dlqMessage = new Message[1];
    ActiveMQDestination dlqDestination = new ActiveMQQueue("ActiveMQ.DLQ");
    MessageConsumer dlqConsumer = session.createConsumer(dlqDestination);
    final CountDownLatch gotDlqMessage = new CountDownLatch(1);
    dlqConsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("DLQ Message Received: " + message);
            dlqMessage[0] = message;
            gotDlqMessage.countDown();
        }
    });
    MessageConsumer consumer = session.createConsumer(queue);
    final int maxDeliveries = getRedeliveryPolicy().getMaximumRedeliveries();
    final CountDownLatch gotMessage = new CountDownLatch(maxDeliveries);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("Message Received: " + message);
            gotMessage.countDown();
            throw new RuntimeException(getName() + " force a redelivery");
        }
    });
    assertTrue("got message before retry expiry", gotMessage.await(20, TimeUnit.SECONDS));
    // check DLQ
    assertTrue("got dlq message", gotDlqMessage.await(20, TimeUnit.SECONDS));
    // check DLQ message cause is captured
    message = dlqMessage[0];
    assertNotNull("dlq message captured", message);
    String cause = message.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    LOG.info("DLQ'd message cause reported as: {}", cause);
    assertTrue("cause 'cause' exception is remembered", cause.contains("RuntimeException"));
    assertTrue("is correct exception", cause.contains(getName()));
    assertTrue("cause exception is remembered", cause.contains("Throwable"));
    assertTrue("cause policy is remembered", cause.contains("RedeliveryPolicy"));
    session.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) Session(javax.jms.Session)

Example 28 with ActiveMQDestination

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

the class DestinationListenerTest method onDestinationEvent.

@Override
public void onDestinationEvent(DestinationEvent event) {
    ActiveMQDestination destination = event.getDestination();
    if (event.isAddOperation()) {
        LOG.info("Added:   " + destination);
        newDestinations.add(destination);
    } else {
        LOG.info("Removed: " + destination);
        newDestinations.remove(destination);
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 29 with ActiveMQDestination

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

the class JmsTopicWildcardSendReceiveTest method testReceiveWildcardTopicEndAsterisk.

public void testReceiveWildcardTopicEndAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createTopic(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination6 = (ActiveMQDestination) session.createTopic("TEST.ONE.*");
    consumer = session.createConsumer(destination6);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination3, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 30 with ActiveMQDestination

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

the class JmsTopicWildcardSendReceiveTest method testReceiveWildcardTopicMidAsterisk.

public void testReceiveWildcardTopicMidAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination4 = (ActiveMQDestination) session.createTopic(destination4String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination8 = (ActiveMQDestination) session.createTopic("TEST.*.ONE");
    consumer = session.createConsumer(destination8);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination4, destination4String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)165 Session (javax.jms.Session)62 MessageConsumer (javax.jms.MessageConsumer)49 Message (org.apache.activemq.command.Message)46 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)45 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)44 SessionInfo (org.apache.activemq.command.SessionInfo)44 ProducerInfo (org.apache.activemq.command.ProducerInfo)42 Test (org.junit.Test)41 Message (javax.jms.Message)40 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)40 TextMessage (javax.jms.TextMessage)31 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)24 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)22 MessageProducer (javax.jms.MessageProducer)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 ActiveMQMessageProducer (org.apache.activemq.ActiveMQMessageProducer)12 MessageAck (org.apache.activemq.command.MessageAck)12 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)11