Search in sources :

Example 41 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class ThreeBrokerTopicNetworkTest method testAllConnectedBrokerNetworkDurableSubTTL.

public void testAllConnectedBrokerNetworkDurableSubTTL() throws Exception {
    int networkTTL = 2;
    boolean conduitSubs = true;
    // Setup ring broker network
    bridgeBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    bridgeBrokers("BrokerB", "BrokerA", dynamicOnly, networkTTL, conduitSubs);
    bridgeBrokers("BrokerB", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    bridgeBrokers("BrokerC", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    bridgeBrokers("BrokerA", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    bridgeBrokers("BrokerC", "BrokerA", dynamicOnly, networkTTL, conduitSubs);
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", true);
    // Setup consumers
    MessageConsumer clientA = createDurableSubscriber("BrokerA", (Topic) dest, "clientA");
    MessageConsumer clientB = createDurableSubscriber("BrokerB", (Topic) dest, "clientB");
    MessageConsumer clientC = createDurableSubscriber("BrokerC", (Topic) dest, "clientC");
    // let consumers propagate around the network
    Thread.sleep(2000);
    // Send messages
    sendMessages("BrokerA", dest, 1);
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
    msgsA.waitForMessagesToArrive(1);
    msgsB.waitForMessagesToArrive(1);
    msgsC.waitForMessagesToArrive(1);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    assertEquals(1, msgsA.getMessageCount());
    assertEquals(1, msgsB.getMessageCount());
    assertEquals(1, msgsC.getMessageCount());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 42 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class ThreeBrokerVirtualTopicNetworkTest method testNetworkVirtualTopic.

public void testNetworkVirtualTopic() throws Exception {
    int networkTTL = 6;
    boolean conduitSubs = true;
    // Setup broker networks
    bridgeAndConfigureBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerA", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerB", "BrokerA", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerB", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerC", "BrokerA", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerC", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", true);
    // Setup consumers
    MessageConsumer clientA = createConsumer("BrokerA", createDestination("Consumer.A.TEST.FOO", false));
    MessageConsumer clientB = createConsumer("BrokerB", createDestination("Consumer.B.TEST.FOO", false));
    MessageConsumer clientC = createConsumer("BrokerC", createDestination("Consumer.C.TEST.FOO", false));
    Thread.sleep(2000);
    // Send messages
    sendMessages("BrokerA", dest, 1);
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
    msgsA.waitForMessagesToArrive(1);
    msgsB.waitForMessagesToArrive(1);
    msgsC.waitForMessagesToArrive(1);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    assertEquals(1, msgsA.getMessageCount());
    assertEquals(1, msgsB.getMessageCount());
    assertEquals(1, msgsC.getMessageCount());
    // restart to ensure no hanging messages
    LOG.info("Restarting brokerA");
    BrokerItem brokerItem = brokers.remove("BrokerA");
    if (brokerItem != null) {
        brokerItem.destroy();
    }
    BrokerService restartedBroker = createAndConfigureBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?useJmx=false"));
    bridgeAndConfigureBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerA", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    restartedBroker.start();
    waitForBridgeFormation();
    clientA = createConsumer("BrokerA", createDestination("Consumer.A.TEST.FOO", false));
    LOG.info("recreated clientA");
    Thread.sleep(2000);
    sendMessages("BrokerA", dest, 10);
    msgsA = getConsumerMessages("BrokerA", clientA);
    msgsA.waitForMessagesToArrive(10);
    msgsB.waitForMessagesToArrive(11);
    msgsC.waitForMessagesToArrive(11);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    LOG.info("MessagesA: " + msgsA.getMessageIds());
    assertEquals(10, msgsA.getMessageCount());
    assertEquals(11, msgsB.getMessageCount());
    assertEquals(11, msgsC.getMessageCount());
    // restart to ensure no hanging messages
    LOG.info("Restarting brokerA again");
    brokerItem = brokers.remove("BrokerA");
    if (brokerItem != null) {
        brokerItem.destroy();
    }
    restartedBroker = createAndConfigureBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?useJmx=false"));
    bridgeAndConfigureBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduitSubs);
    bridgeAndConfigureBrokers("BrokerA", "BrokerC", dynamicOnly, networkTTL, conduitSubs);
    restartedBroker.start();
    waitForBridgeFormation();
    clientA = createConsumer("BrokerA", createDestination("Consumer.A.TEST.FOO", false));
    LOG.info("recreated clientA again");
    Thread.sleep(2000);
    msgsA = getConsumerMessages("BrokerA", clientA);
    // ensure we don't get any more messages
    Thread.sleep(5000);
    LOG.info("Extra MessagesA: " + msgsA.getMessageIds());
    assertEquals(0, msgsA.getMessageCount());
    assertEquals(11, msgsB.getMessageCount());
    assertEquals(11, msgsC.getMessageCount());
}
Also used : VirtualDestination(org.apache.activemq.broker.region.virtual.VirtualDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 43 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class SingleBrokerVirtualDestinationsWithWildcardTest method sendReceive.

public void sendReceive(String dest1, boolean topic1, String dest2, boolean topic2, int send, int expected) throws Exception {
    MessageConsumer client = createConsumer("BrokerA", createDestination(dest2, topic2));
    Thread.sleep(1000);
    sendMessages("BrokerA", createDestination(dest1, topic1), send);
    MessageIdList msgs = getConsumerMessages("BrokerA", client);
    msgs.setMaximumDuration(1000);
    assertEquals(expected, msgs.getMessageCount());
    client.close();
    Thread.sleep(500);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 44 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class ThreeBrokerQueueNetworkTest method testAllConnectedWithSpare.

public void testAllConnectedWithSpare() throws Exception {
    bridgeAllBrokers("default", 3, false);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    int messageCount = 2000;
    CountDownLatch messagesReceived = new CountDownLatch(messageCount);
    MessageConsumer clientA = createConsumer("BrokerA", dest, messagesReceived);
    // ensure advisory percolation.
    Thread.sleep(2000);
    // Send messages
    sendMessages("BrokerB", dest, messageCount);
    assertTrue("messaged received within time limit", messagesReceived.await(30, TimeUnit.SECONDS));
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    assertEquals(messageCount, msgsA.getMessageCount());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 45 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class ThreeBrokerQueueNetworkTest method testAllConnectedUsingMulticastProducerConsumerOnA.

public void testAllConnectedUsingMulticastProducerConsumerOnA() throws Exception {
    bridgeAllBrokers("default", 3, false);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    int messageCount = 2000;
    CountDownLatch messagesReceived = new CountDownLatch(messageCount);
    MessageConsumer clientA = createConsumer("BrokerA", dest, messagesReceived);
    // Let's try to wait for advisory percolation.
    Thread.sleep(1000);
    // Send messages
    sendMessages("BrokerA", dest, messageCount);
    assertTrue(messagesReceived.await(30, TimeUnit.SECONDS));
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    assertEquals(messageCount, msgsA.getMessageCount());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) MessageIdList(org.apache.activemq.util.MessageIdList)

Aggregations

MessageIdList (org.apache.activemq.util.MessageIdList)63 MessageConsumer (javax.jms.MessageConsumer)58 Destination (javax.jms.Destination)34 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)31 CountDownLatch (java.util.concurrent.CountDownLatch)8 Connection (javax.jms.Connection)6 VirtualDestination (org.apache.activemq.broker.region.virtual.VirtualDestination)5 Test (org.junit.Test)5 URI (java.net.URI)4 BrokerService (org.apache.activemq.broker.BrokerService)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 NetworkConnector (org.apache.activemq.network.NetworkConnector)4 HashMap (java.util.HashMap)3 Session (javax.jms.Session)3 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)3 TestSupport.getDestination (org.apache.activemq.TestSupport.getDestination)3 Destination (org.apache.activemq.broker.region.Destination)3 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)3 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3