Search in sources :

Example 51 with MessageIdList

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

the class ThreeBrokerQueueNetworkTest method testMigrateConsumer.

// use case: for maintenance, migrate consumers and producers from one
// node in the network to another so node can be replaced/updated
public void testMigrateConsumer() throws Exception {
    boolean suppressQueueDuplicateSubscriptions = true;
    boolean decreaseNetworkConsumerPriority = true;
    bridgeAllBrokers("default", 3, suppressQueueDuplicateSubscriptions, decreaseNetworkConsumerPriority);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    LOG.info("Consumer on A");
    MessageConsumer clientA = createConsumer("BrokerA", dest);
    // ensure advisors have percolated
    Thread.sleep(2000);
    LOG.info("Consumer on B");
    int messageCount = 2000;
    CountDownLatch messagesReceived = new CountDownLatch(messageCount);
    MessageConsumer clientB = createConsumer("BrokerB", dest, messagesReceived);
    // make the consumer slow so that any network consumer has a chance, even
    // if it has a lower priority
    MessageIdList msgs = getConsumerMessages("BrokerB", clientB);
    msgs.setProcessingDelay(10);
    // ensure advisors have percolated
    Thread.sleep(2000);
    LOG.info("Close consumer on A");
    clientA.close();
    // ensure advisors have percolated
    Thread.sleep(2000);
    LOG.info("Send to B");
    sendMessages("BrokerB", dest, messageCount);
    // Let's try to wait for any messages.
    assertTrue("messages are received within limit", messagesReceived.await(60, TimeUnit.SECONDS));
    assertEquals(messageCount, msgs.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 52 with MessageIdList

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

the class ThreeBrokerQueueNetworkTest method testABandCBbrokerNetwork.

/**
 * BrokerA -> BrokerB <- BrokerC
 */
public void testABandCBbrokerNetwork() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB");
    bridgeBrokers("BrokerC", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer clientB = createConsumer("BrokerB", dest);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    sendMessages("BrokerC", dest, MESSAGE_COUNT);
    // Get message count
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 2);
    assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 53 with MessageIdList

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

the class StaticNetworkTest method testStaticNetwork.

public void testStaticNetwork() throws Exception {
    // Setup destination
    ActiveMQDestination dest = createDestination("TEST", false);
    ActiveMQDestination dest1 = createDestination("TEST1", false);
    NetworkConnector bridgeAB = bridgeBrokers("BrokerA", "BrokerB", true);
    bridgeAB.addStaticallyIncludedDestination(dest);
    bridgeAB.setStaticBridge(true);
    startAllBrokers();
    waitForBridgeFormation();
    MessageConsumer consumer1 = createConsumer("BrokerB", dest);
    MessageConsumer consumer2 = createConsumer("BrokerB", dest1);
    Thread.sleep(1000);
    sendMessages("BrokerA", dest, 1);
    sendMessages("BrokerA", dest1, 1);
    MessageIdList msgs1 = getConsumerMessages("BrokerB", consumer1);
    MessageIdList msgs2 = getConsumerMessages("BrokerB", consumer2);
    msgs1.waitForMessagesToArrive(1);
    Thread.sleep(1000);
    assertEquals(1, msgs1.getMessageCount());
    assertEquals(0, msgs2.getMessageCount());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) NetworkConnector(org.apache.activemq.network.NetworkConnector) MessageIdList(org.apache.activemq.util.MessageIdList) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 54 with MessageIdList

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

the class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest method testRemoteBrokerHasNoConsumer.

/**
 * BrokerA -> BrokerB
 */
public void testRemoteBrokerHasNoConsumer() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB");
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", true);
    // Setup consumers
    MessageConsumer clientA = createConsumer("BrokerA", dest);
    // Send messages
    sendMessages("BrokerA", dest, MESSAGE_COUNT);
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    msgsA.waitForMessagesToArrive(MESSAGE_COUNT);
    assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 55 with MessageIdList

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

the class TwoBrokerMessageNotSentToRemoteWhenNoConsumerTest method testDuplexStaticRemoteBrokerHasNoConsumer.

/**
 * BrokerA -> BrokerB && BrokerB -> BrokerA
 */
public void testDuplexStaticRemoteBrokerHasNoConsumer() throws Exception {
    // Setup broker networks
    boolean dynamicOnly = true;
    int networkTTL = 2;
    boolean conduit = true;
    bridgeBrokers("BrokerA", "BrokerB", dynamicOnly, networkTTL, conduit);
    bridgeBrokers("BrokerB", "BrokerA", dynamicOnly, networkTTL, conduit);
    startAllBrokers();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    MessageConsumer clientA = createConsumer("BrokerA", dest);
    Thread.sleep(2 * 1000);
    int messageCount = 2000;
    // Send messages
    sendMessages("BrokerA", dest, messageCount);
    // Get message count
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    msgsA.waitForMessagesToArrive(messageCount);
    assertEquals(messageCount, msgsA.getMessageCount());
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) 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