Search in sources :

Example 31 with MessageIdList

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

the class JmsMultipleClientsTestSupport method assertTotalMessagesReceived.

protected void assertTotalMessagesReceived(int msgCount) {
    allMessagesList.assertMessagesReceivedNoWait(msgCount);
    // now lets count the individual messages received
    int totalMsg = 0;
    for (Iterator<MessageConsumer> i = consumers.keySet().iterator(); i.hasNext(); ) {
        MessageIdList messageIdList = consumers.get(i.next());
        totalMsg += messageIdList.getMessageCount();
    }
    assertEquals("Total of consumers message count", msgCount, totalMsg);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 32 with MessageIdList

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

the class JmsMultipleClientsTestSupport method startConsumers.

protected void startConsumers(ConnectionFactory factory, Destination dest) throws Exception {
    MessageConsumer consumer;
    for (int i = 0; i < consumerCount; i++) {
        if (durable && topic) {
            consumer = createDurableSubscriber(factory.createConnection(), dest, "consumer" + (i + 1));
        } else {
            consumer = createMessageConsumer(factory.createConnection(), dest);
        }
        MessageIdList list = new MessageIdList();
        list.setParent(allMessagesList);
        consumer.setMessageListener(list);
        consumers.put(consumer, list);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 33 with MessageIdList

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

the class AbortSlowConsumer0Test method testOnlyOneSlowConsumerIsAborted.

@Test
public void testOnlyOneSlowConsumerIsAborted() throws Exception {
    consumerCount = 10;
    startConsumers(destination);
    Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next();
    consumertoAbort.getValue().setProcessingDelay(8 * 1000);
    for (Connection c : connections) {
        c.setExceptionListener(this);
    }
    startProducers(destination, 100);
    allMessagesList.waitForMessagesToArrive(99);
    allMessagesList.assertAtLeastMessagesReceived(99);
    consumertoAbort.getValue().assertMessagesReceived(1);
    TimeUnit.SECONDS.sleep(5);
    consumertoAbort.getValue().assertAtMostMessagesReceived(1);
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageIdList(org.apache.activemq.util.MessageIdList) Test(org.junit.Test)

Example 34 with MessageIdList

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

the class AbortSlowConsumer0Test method testSlowConsumerIsAbortedViaJmx.

@Test
public void testSlowConsumerIsAbortedViaJmx() throws Exception {
    // so jmx does the abort
    underTest.setMaxSlowDuration(60 * 1000);
    startConsumers(withPrefetch(2, destination));
    Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next();
    consumertoAbort.getValue().setProcessingDelay(8 * 1000);
    for (Connection c : connections) {
        c.setExceptionListener(this);
    }
    startProducers(destination, 100);
    consumertoAbort.getValue().assertMessagesReceived(1);
    ActiveMQDestination amqDest = (ActiveMQDestination) destination;
    ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
    DestinationViewMBean queue = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
    ObjectName slowConsumerPolicyMBeanName = queue.getSlowConsumerStrategy();
    assertNotNull(slowConsumerPolicyMBeanName);
    AbortSlowConsumerStrategyViewMBean abortPolicy = (AbortSlowConsumerStrategyViewMBean) broker.getManagementContext().newProxyInstance(slowConsumerPolicyMBeanName, AbortSlowConsumerStrategyViewMBean.class, true);
    TimeUnit.SECONDS.sleep(3);
    TabularData slowOnes = abortPolicy.getSlowConsumers();
    assertEquals("one slow consumers", 1, slowOnes.size());
    LOG.info("slow ones:" + slowOnes);
    CompositeData slowOne = (CompositeData) slowOnes.values().iterator().next();
    LOG.info("Slow one: " + slowOne);
    assertTrue("we have an object name", slowOne.get("subscription") instanceof ObjectName);
    abortPolicy.abortConsumer((ObjectName) slowOne.get("subscription"));
    consumertoAbort.getValue().assertAtMostMessagesReceived(1);
    slowOnes = abortPolicy.getSlowConsumers();
    assertEquals("no slow consumers left", 0, slowOnes.size());
    // verify mbean gone with destination
    broker.getAdminView().removeTopic(amqDest.getPhysicalName());
    try {
        abortPolicy.getSlowConsumers();
        fail("expect not found post destination removal");
    } catch (UndeclaredThrowableException expected) {
        assertTrue("correct exception: " + expected.getCause(), expected.getCause() instanceof InstanceNotFoundException);
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) CompositeData(javax.management.openmbean.CompositeData) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Connection(javax.jms.Connection) AbortSlowConsumerStrategyViewMBean(org.apache.activemq.broker.jmx.AbortSlowConsumerStrategyViewMBean) MessageIdList(org.apache.activemq.util.MessageIdList) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 35 with MessageIdList

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

the class AbortSlowConsumer1Test method testSlowConsumerIsAborted.

@Test(timeout = 60 * 1000)
public void testSlowConsumerIsAborted() throws Exception {
    startConsumers(destination);
    Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next();
    consumertoAbort.getValue().setProcessingDelay(8 * 1000);
    for (Connection c : connections) {
        c.setExceptionListener(this);
    }
    startProducers(destination, 100);
    consumertoAbort.getValue().assertMessagesReceived(1);
    TimeUnit.SECONDS.sleep(5);
    consumertoAbort.getValue().assertAtMostMessagesReceived(1);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageIdList(org.apache.activemq.util.MessageIdList) Test(org.junit.Test)

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