Search in sources :

Example 6 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class TwoBrokerVirtualTopicForwardingTest method testDontBridgeQueuesWithBothTypesConsumers.

public void testDontBridgeQueuesWithBothTypesConsumers() throws Exception {
    dontBridgeVirtualTopicConsumerQueues("BrokerA", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    MessageConsumer clientA = createConsumer("BrokerA", createDestination("Consumer.A.VirtualTopic.tempTopic", false));
    MessageConsumer clientB = createConsumer("BrokerB", createDestination("Consumer.B.VirtualTopic.tempTopic", false));
    MessageConsumer clientC = createConsumer("BrokerB", createDestination("VirtualTopic.tempTopic", true));
    // give a sec to let advisories propagate
    Thread.sleep(500);
    ActiveMQQueue queueA = new ActiveMQQueue("Consumer.A.VirtualTopic.tempTopic");
    Destination destination = getDestination(brokers.get("BrokerA").broker, queueA);
    assertEquals(1, destination.getConsumers().size());
    ActiveMQQueue queueB = new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic");
    destination = getDestination(brokers.get("BrokerA").broker, queueB);
    assertNull(destination);
    ActiveMQTopic virtualTopic = new ActiveMQTopic("VirtualTopic.tempTopic");
    assertNotNull(getDestination(brokers.get("BrokerA").broker, virtualTopic));
    assertNotNull(getDestination(brokers.get("BrokerB").broker, virtualTopic));
    // send some messages
    sendMessages("BrokerA", virtualTopic, 1);
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    msgsA.waitForMessagesToArrive(1);
    msgsB.waitForMessagesToArrive(1);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    assertEquals(1, msgsA.getMessageCount());
    assertEquals(1, msgsB.getMessageCount());
}
Also used : TestSupport.getDestination(org.apache.activemq.TestSupport.getDestination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 7 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class TwoBrokerVirtualTopicForwardingTest method testBridgeVirtualTopicQueues.

public void testBridgeVirtualTopicQueues() throws Exception {
    bridgeAndConfigureBrokers("BrokerA", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    MessageConsumer clientA = createConsumer("BrokerA", createDestination("Consumer.A.VirtualTopic.tempTopic", false));
    MessageConsumer clientB = createConsumer("BrokerB", createDestination("Consumer.B.VirtualTopic.tempTopic", false));
    // give a sec to let advisories propagate
    Thread.sleep(500);
    ActiveMQQueue queueA = new ActiveMQQueue("Consumer.A.VirtualTopic.tempTopic");
    Destination destination = getDestination(brokers.get("BrokerA").broker, queueA);
    assertEquals(1, destination.getConsumers().size());
    ActiveMQQueue queueB = new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic");
    destination = getDestination(brokers.get("BrokerA").broker, queueB);
    assertEquals(1, destination.getConsumers().size());
    ActiveMQTopic virtualTopic = new ActiveMQTopic("VirtualTopic.tempTopic");
    assertNull(getDestination(brokers.get("BrokerA").broker, virtualTopic));
    assertNull(getDestination(brokers.get("BrokerB").broker, virtualTopic));
    // send some messages
    sendMessages("BrokerA", virtualTopic, 1);
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    msgsA.waitForMessagesToArrive(1);
    msgsB.waitForMessagesToArrive(1);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    assertEquals(1, msgsA.getMessageCount());
    assertEquals(1, msgsB.getMessageCount());
}
Also used : TestSupport.getDestination(org.apache.activemq.TestSupport.getDestination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 8 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class TwoBrokerVirtualTopicForwardingTest method testDontBridgeQueuesWithOnlyQueueConsumers.

public void testDontBridgeQueuesWithOnlyQueueConsumers() throws Exception {
    dontBridgeVirtualTopicConsumerQueues("BrokerA", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    MessageConsumer clientA = createConsumer("BrokerA", createDestination("Consumer.A.VirtualTopic.tempTopic", false));
    MessageConsumer clientB = createConsumer("BrokerB", createDestination("Consumer.B.VirtualTopic.tempTopic", false));
    // give a sec to let advisories propagate
    Thread.sleep(500);
    ActiveMQQueue queueA = new ActiveMQQueue("Consumer.A.VirtualTopic.tempTopic");
    Destination destination = getDestination(brokers.get("BrokerA").broker, queueA);
    assertEquals(1, destination.getConsumers().size());
    ActiveMQQueue queueB = new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic");
    destination = getDestination(brokers.get("BrokerA").broker, queueB);
    assertNull(destination);
    ActiveMQTopic virtualTopic = new ActiveMQTopic("VirtualTopic.tempTopic");
    assertNull(getDestination(brokers.get("BrokerA").broker, virtualTopic));
    assertNull(getDestination(brokers.get("BrokerB").broker, virtualTopic));
    // send some messages
    sendMessages("BrokerA", virtualTopic, 1);
    MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
    MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
    msgsA.waitForMessagesToArrive(1);
    msgsB.waitForMessagesToArrive(0);
    // ensure we don't get any more messages
    Thread.sleep(2000);
    assertEquals(1, msgsA.getMessageCount());
    assertEquals(0, msgsB.getMessageCount());
}
Also used : TestSupport.getDestination(org.apache.activemq.TestSupport.getDestination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 9 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class NoDuplicateOnTopicNetworkTest method testProducerConsumerTopic.

public void testProducerConsumerTopic() throws Exception {
    final CountDownLatch consumerStarted = new CountDownLatch(1);
    Thread producerThread = new Thread(new Runnable() {

        @Override
        public void run() {
            TopicWithDuplicateMessages producer = new TopicWithDuplicateMessages();
            producer.setBrokerURL(BROKER_1);
            producer.setTopicName(TOPIC_NAME);
            try {
                producer.produce();
            } catch (JMSException e) {
                fail("Unexpected " + e);
            }
        }
    });
    final TopicWithDuplicateMessages consumer = new TopicWithDuplicateMessages();
    Thread consumerThread = new Thread(new Runnable() {

        @Override
        public void run() {
            consumer.setBrokerURL(BROKER_2);
            consumer.setTopicName(TOPIC_NAME);
            try {
                consumer.consumer();
                consumerStarted.countDown();
                consumer.getLatch().await(60, TimeUnit.SECONDS);
            } catch (Exception e) {
                fail("Unexpected " + e);
            }
        }
    });
    consumerThread.start();
    LOG.info("Started Consumer");
    assertTrue("consumer started eventually", consumerStarted.await(10, TimeUnit.SECONDS));
    // ensure subscription has percolated though the network
    Thread.sleep(2000);
    // verify network consumer priority
    final RegionBroker regionBroker = (RegionBroker) broker1.getRegionBroker();
    assertTrue("Found network destination with priority as expected", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Map<ActiveMQDestination, Destination> destinationMap = regionBroker.getTopicRegion().getDestinationMap();
            LOG.info("destinations: " + destinationMap.keySet());
            boolean found = false;
            for (Destination destination : destinationMap.values()) {
                List<Subscription> subscriptions = destination.getConsumers();
                LOG.info(destination + " subscriptions: " + subscriptions);
                for (Subscription subscription : subscriptions) {
                    if (subscription.getConsumerInfo().isNetworkSubscription()) {
                        LOG.info("subscription: " + subscription + ", priority: " + subscription.getConsumerInfo().getPriority());
                        assertTrue("priority is < our base: " + subscription.getConsumerInfo().getPriority(), subscription.getConsumerInfo().getPriority() <= BASE_PRIORITY);
                        found = true;
                    }
                }
            }
            return found;
        }
    }));
    producerThread.start();
    LOG.info("Started Producer");
    producerThread.join();
    consumerThread.join();
    int duplicateCount = 0;
    Map<String, String> map = new HashMap<>();
    for (String msg : consumer.getMessageStrings()) {
        if (map.containsKey(msg)) {
            LOG.info("got duplicate: " + msg);
            duplicateCount++;
        }
        map.put(msg, msg);
    }
    consumer.unSubscribe();
    if (suppressDuplicateTopicSubs || dispatchPolicy instanceof PriorityNetworkDispatchPolicy) {
        assertEquals("no duplicates", 0, duplicateCount);
        assertEquals("got all required messages: " + map.size(), consumer.getNumMessages(), map.size());
    } else {
        assertTrue("we can get some duplicates: " + duplicateCount, duplicateCount >= 0);
        if (duplicateCount == 0) {
            assertEquals("got all required messages: " + map.size(), consumer.getNumMessages(), map.size());
        }
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(org.apache.activemq.broker.region.Destination) RegionBroker(org.apache.activemq.broker.region.RegionBroker) HashMap(java.util.HashMap) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) JMSException(javax.jms.JMSException) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) PriorityNetworkDispatchPolicy(org.apache.activemq.broker.region.policy.PriorityNetworkDispatchPolicy) Subscription(org.apache.activemq.broker.region.Subscription)

Example 10 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class DurableSubscriptionUnsubscribeTest method assertCount.

private void assertCount(int all, int active) throws Exception {
    int inactive = all - active;
    // broker check
    Destination destination = broker.getDestination(topic);
    List<Subscription> subs = destination.getConsumers();
    int cActive = 0, cInactive = 0;
    for (Subscription sub : subs) {
        if (sub instanceof DurableTopicSubscription) {
            DurableTopicSubscription durable = (DurableTopicSubscription) sub;
            if (durable.isActive())
                cActive++;
            else
                cInactive++;
        }
    }
    assertEquals(active, cActive);
    assertEquals(inactive, cInactive);
    // admin view
    ObjectName[] subscriptions = broker.getAdminView().getDurableTopicSubscribers();
    assertEquals(active, subscriptions.length);
    subscriptions = broker.getAdminView().getInactiveDurableTopicSubscribers();
    assertEquals(inactive, subscriptions.length);
    // check the strange false MBean
    if (all == 0)
        assertEquals(0, countMBean());
    // check if we got all advisories
    assertEquals(100, all + advisories.get());
}
Also used : Destination(org.apache.activemq.broker.region.Destination) DurableTopicSubscription(org.apache.activemq.broker.region.DurableTopicSubscription) Subscription(org.apache.activemq.broker.region.Subscription) DurableTopicSubscription(org.apache.activemq.broker.region.DurableTopicSubscription) ObjectName(javax.management.ObjectName)

Aggregations

Destination (org.apache.activemq.broker.region.Destination)18 MessageConsumer (javax.jms.MessageConsumer)6 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)6 TopicConnection (javax.jms.TopicConnection)5 TopicSession (javax.jms.TopicSession)5 TopicSubscriber (javax.jms.TopicSubscriber)5 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)5 Session (javax.jms.Session)4 MessageProducer (javax.jms.MessageProducer)3 TestSupport.getDestination (org.apache.activemq.TestSupport.getDestination)3 RegionBroker (org.apache.activemq.broker.region.RegionBroker)3 Subscription (org.apache.activemq.broker.region.Subscription)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 MessageIdList (org.apache.activemq.util.MessageIdList)3 ObjectName (javax.management.ObjectName)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BytesMessage (javax.jms.BytesMessage)1