Search in sources :

Example 1 with DurableSubscriptionViewMBean

use of org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean in project activemq-artemis by apache.

the class TopicDurableConnectStatsTest method testPendingTopicStat.

public void testPendingTopicStat() throws Exception {
    Connection consumerCon = createConnection("cliId1");
    Session consumerSession = consumerCon.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = consumerSession.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
    assertNotNull(consumer1);
    DurableSubscriptionViewMBean subscriber1 = null;
    ObjectName query = new ObjectName(domain + ":type=Broker,brokerName=" + getName(true) + ",destinationType=Topic,destinationName=" + topic.getTopicName() + ",endpoint=Consumer,clientId=cliId1,consumerId=*");
    java.util.Set<ObjectName> set = mbeanServer.queryNames(query, null);
    ObjectName subscriberObjName1 = set.iterator().next();
    subscriber1 = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, subscriberObjName1, DurableSubscriptionViewMBean.class, true);
    LOG.info("Beginning Pending Queue Size count: " + subscriber1.getPendingQueueSize());
    LOG.info("Prefetch Limit: " + subscriber1.getPrefetchSize());
    assertEquals("no pending", 0, subscriber1.getPendingQueueSize());
    assertEquals("Prefetch Limit ", 10, subscriber1.getPrefetchSize());
    Connection producerCon = createConnection("x");
    Session producerSessions = producerCon.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSessions.createProducer(topic);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    int i = 0;
    for (; i < numMessages; i++) {
        if (i == 15) {
            // kill consumer
            LOG.info("Killing consumer at 15");
            consumerSession.close();
            consumerCon.close();
        }
        TextMessage message = producerSessions.createTextMessage(createMessageText(i));
        message.setJMSExpiration(0);
        message.setStringProperty("filter", "true");
        producer.send(topic, message);
        producerSessions.commit();
    }
    LOG.info("Sent " + i + " messages in total");
    producerCon.close();
    LOG.info("Pending Queue Size count: " + subscriber1.getPendingQueueSize());
    assertEquals("pending as expected", 20, subscriber1.getPendingQueueSize());
    LOG.info("Re-connect client and consume messages");
    Connection con2 = createConnection("cliId1");
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer2 = session2.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
    final Listener listener = new Listener();
    consumer2.setMessageListener(listener);
    assertTrue("received all sent", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return numMessages == listener.count;
        }
    }));
    LOG.info("Received: " + listener.count);
    int pq = subscriber1.getPendingQueueSize();
    LOG.info("Pending Queue Size count: " + pq);
    assertEquals("Pending queue after consumed", 0, pq);
    session2.close();
    con2.close();
    LOG.info("FINAL Pending Queue Size count (after consumer close): " + subscriber1.getPendingQueueSize());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageListener(javax.jms.MessageListener) Connection(javax.jms.Connection) MBeanServerConnection(javax.management.MBeanServerConnection) DurableSubscriptionViewMBean(org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ObjectName(javax.management.ObjectName)

Example 2 with DurableSubscriptionViewMBean

use of org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean in project activemq-artemis by apache.

the class MQTTNetworkOfBrokersFailoverTest method assertOneDurableSubOn.

@SuppressWarnings("unused")
private void assertOneDurableSubOn(BrokerService broker, String subName) throws Exception {
    BrokerViewMBean brokerView = broker.getAdminView();
    ObjectName[] activeDurableSubs = brokerView.getDurableTopicSubscribers();
    ObjectName[] inactiveDurableSubs = brokerView.getInactiveDurableTopicSubscribers();
    ObjectName[] allDurables = (ObjectName[]) ArrayUtils.addAll(activeDurableSubs, inactiveDurableSubs);
    assertEquals(1, allDurables.length);
    // at this point our assertions should prove that we have only on durable sub
    DurableSubscriptionViewMBean durableSubView = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(allDurables[0], DurableSubscriptionViewMBean.class, true);
    assertEquals(subName, durableSubView.getClientId());
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) DurableSubscriptionViewMBean(org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean) ObjectName(javax.management.ObjectName)

Example 3 with DurableSubscriptionViewMBean

use of org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean in project activemq-artemis by apache.

the class DurableSubscriptionOffline2Test method testJMXCountersWithOfflineSubs.

@Test(timeout = 60 * 1000)
public void testJMXCountersWithOfflineSubs() throws Exception {
    // create durable subscription 1
    Connection con = createConnection("cliId1");
    Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId", null, true);
    session.close();
    con.close();
    // restart broker
    broker.stop();
    createBroker(false);
    // send messages
    con = createConnection();
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(null);
    int sent = 0;
    for (int i = 0; i < 10; i++) {
        sent++;
        Message message = session.createMessage();
        producer.send(topic, message);
    }
    session.close();
    con.close();
    // consume some messages
    con = createConnection("cliId1");
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
    for (int i = 0; i < sent / 2; i++) {
        Message m = consumer.receive(4000);
        assertNotNull("got message: " + i, m);
        LOG.info("Got :" + i + ", " + m);
    }
    // check some counters while active
    ObjectName activeDurableSubName = broker.getAdminView().getDurableTopicSubscribers()[0];
    LOG.info("active durable sub name: " + activeDurableSubName);
    final DurableSubscriptionViewMBean durableSubscriptionView = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(activeDurableSubName, DurableSubscriptionViewMBean.class, true);
    assertTrue("is active", durableSubscriptionView.isActive());
    assertEquals("all enqueued", keepDurableSubsActive ? 10 : 0, durableSubscriptionView.getEnqueueCounter());
    assertTrue("correct waiting acks", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 5 == durableSubscriptionView.getMessageCountAwaitingAcknowledge();
        }
    }));
    assertEquals("correct dequeue", 5, durableSubscriptionView.getDequeueCounter());
    ObjectName destinationName = broker.getAdminView().getTopics()[0];
    TopicViewMBean topicView = (TopicViewMBean) broker.getManagementContext().newProxyInstance(destinationName, TopicViewMBean.class, true);
    assertEquals("correct enqueue", 10, topicView.getEnqueueCount());
    assertEquals("still zero dequeue, we don't decrement on each sub ack to stop exceeding the enqueue count with multiple subs", 0, topicView.getDequeueCount());
    assertEquals("inflight", 5, topicView.getInFlightCount());
    session.close();
    con.close();
    // check some counters when inactive
    ObjectName inActiveDurableSubName = broker.getAdminView().getInactiveDurableTopicSubscribers()[0];
    LOG.info("inactive durable sub name: " + inActiveDurableSubName);
    DurableSubscriptionViewMBean durableSubscriptionView1 = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(inActiveDurableSubName, DurableSubscriptionViewMBean.class, true);
    assertTrue("is not active", !durableSubscriptionView1.isActive());
    assertEquals("all enqueued", keepDurableSubsActive ? 10 : 0, durableSubscriptionView1.getEnqueueCounter());
    assertEquals("correct awaiting ack", 0, durableSubscriptionView1.getMessageCountAwaitingAcknowledge());
    assertEquals("correct dequeue", keepDurableSubsActive ? 5 : 0, durableSubscriptionView1.getDequeueCounter());
    // destination view
    assertEquals("correct enqueue", 10, topicView.getEnqueueCount());
    assertEquals("still zero dequeue, we don't decrement on each sub ack to stop exceeding the enqueue count with multiple subs", 0, topicView.getDequeueCount());
    assertEquals("inflight back to 0 after deactivate", 0, topicView.getInFlightCount());
    // consume the rest
    con = createConnection("cliId1");
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
    for (int i = 0; i < sent / 2; i++) {
        Message m = consumer.receive(30000);
        assertNotNull("got message: " + i, m);
        LOG.info("Got :" + i + ", " + m);
    }
    activeDurableSubName = broker.getAdminView().getDurableTopicSubscribers()[0];
    LOG.info("durable sub name: " + activeDurableSubName);
    final DurableSubscriptionViewMBean durableSubscriptionView2 = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(activeDurableSubName, DurableSubscriptionViewMBean.class, true);
    assertTrue("is active", durableSubscriptionView2.isActive());
    assertEquals("all enqueued", keepDurableSubsActive ? 10 : 0, durableSubscriptionView2.getEnqueueCounter());
    assertTrue("correct dequeue", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            long val = durableSubscriptionView2.getDequeueCounter();
            LOG.info("dequeue count:" + val);
            return 10 == val;
        }
    }));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TopicViewMBean(org.apache.activemq.broker.jmx.TopicViewMBean) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) DurableSubscriptionViewMBean(org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean) Session(javax.jms.Session) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 4 with DurableSubscriptionViewMBean

use of org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean in project activemq-artemis by apache.

the class DurableSubscriptionUnsubscribeTest method doJMXUnsubscribe.

public void doJMXUnsubscribe(boolean restart) throws Exception {
    createSubscriptions();
    createAdvisorySubscription();
    Thread.sleep(1000);
    assertCount(100, 0);
    if (restart) {
        restartBroker();
        createAdvisorySubscription();
        assertCount(100, 0);
    }
    ObjectName[] subs = broker.getAdminView().getInactiveDurableTopicSubscribers();
    for (int i = 0; i < subs.length; i++) {
        ObjectName subName = subs[i];
        DurableSubscriptionViewMBean sub = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(subName, DurableSubscriptionViewMBean.class, true);
        sub.destroy();
        if (i % 20 == 0) {
            Thread.sleep(1000);
            assertCount(100 - i - 1, 0);
        }
    }
    Thread.sleep(1000);
    assertCount(0, 0);
    if (restart) {
        restartBroker();
        createAdvisorySubscription();
        assertCount(0, 0);
    }
}
Also used : DurableSubscriptionViewMBean(org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean) ObjectName(javax.management.ObjectName)

Aggregations

ObjectName (javax.management.ObjectName)4 DurableSubscriptionViewMBean (org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean)4 Connection (javax.jms.Connection)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Session (javax.jms.Session)2 Message (javax.jms.Message)1 MessageListener (javax.jms.MessageListener)1 TextMessage (javax.jms.TextMessage)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 BrokerViewMBean (org.apache.activemq.broker.jmx.BrokerViewMBean)1 TopicViewMBean (org.apache.activemq.broker.jmx.TopicViewMBean)1 Test (org.junit.Test)1