Search in sources :

Example 21 with ActiveMQDestination

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

the class BrokerTest method testTopicConsumerOnlySeeMessagesAfterCreation.

public void testTopicConsumerOnlySeeMessagesAfterCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Send the 1st message
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Subscription should skip over the first message
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertNoMessagesLeft(connection1);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 22 with ActiveMQDestination

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

the class BrokerTest method testCompositeSend.

public void testCompositeSend() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationA);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationB);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.request(consumerInfo2);
    // Send the messages to the composite destination.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    for (int i = 0; i < 4; i++) {
        connection1.request(createMessage(producerInfo1, compositeDestination, deliveryMode));
    }
    // destination.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull(m1);
        assertNotNull(m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        assertEquals(compositeDestination, m1.getOriginalDestination());
        assertEquals(compositeDestination, m2.getOriginalDestination());
        connection1.request(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.request(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
    connection1.send(closeConnectionInfo(connectionInfo1));
    connection2.send(closeConnectionInfo(connectionInfo2));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 23 with ActiveMQDestination

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

the class BrokerTest method testWildcardConsume.

public void testWildcardConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the wildcard consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("WILD.*.TEST", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // These two message should NOT match the wild card.
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.CARD", destinationType), deliveryMode));
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.TEST", destinationType), deliveryMode));
    // These two message should match the wild card.
    ActiveMQDestination d1 = ActiveMQDestination.createDestination("WILD.CARD.TEST", destinationType);
    connection1.send(createMessage(producerInfo1, d1, deliveryMode));
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d1, m.getDestination());
    ActiveMQDestination d2 = ActiveMQDestination.createDestination("WILD.FOO.TEST", destinationType);
    connection1.request(createMessage(producerInfo1, d2, deliveryMode));
    m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d2, m.getDestination());
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 24 with ActiveMQDestination

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

the class BrokerTest method testGroupedMessagesDeliveredToOnlyOneConsumer.

public void testGroupedMessagesDeliveredToOnlyOneConsumer() 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.send(consumerInfo1);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination, deliveryMode);
        message.setGroupID("TEST-GROUP");
        message.setGroupSequence(i + 1);
        connection1.request(message);
    }
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(consumerInfo2);
    // the first 3
    for (int i = 0; i < 3; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        connection2.request(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    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 25 with ActiveMQDestination

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

the class BrokerTest method testQueueBrowserWith2ConsumersBrowseFirst.

/*
    * change the order of the above test
    */
public void testQueueBrowserWith2ConsumersBrowseFirst() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(10);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // 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(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // as the messages are sent async - need to synchronize the last
    // one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    // no messages present in queue browser as there were no messages when it
    // was created
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) ArrayList(java.util.ArrayList) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) 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