Search in sources :

Example 1 with TopicViewMBean

use of org.apache.activemq.broker.jmx.TopicViewMBean 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 2 with TopicViewMBean

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

the class SimpleAuthenticationPluginTest method testTempDestinations.

public void testTempDestinations() throws Exception {
    Connection conn = factory.createConnection("guest", "password");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String name = "org.apache.activemq:BrokerName=localhost,Type=TempTopic";
    try {
        conn.start();
        TemporaryTopic temp = sess.createTemporaryTopic();
        name += ",Destination=" + temp.getTopicName().replaceAll(":", "_");
        fail("Should have failed creating a temp topic");
    } catch (Exception ignore) {
    }
    ObjectName objName = new ObjectName(name);
    TopicViewMBean mbean = (TopicViewMBean) broker.getManagementContext().newProxyInstance(objName, TopicViewMBean.class, true);
    try {
        System.out.println(mbean.getName());
        fail("Shouldn't have created a temp topic");
    } catch (Exception ignore) {
    }
}
Also used : TopicViewMBean(org.apache.activemq.broker.jmx.TopicViewMBean) Connection(javax.jms.Connection) TransportConnection(org.apache.activemq.broker.TransportConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) JMSException(javax.jms.JMSException) JMSSecurityException(javax.jms.JMSSecurityException) Session(javax.jms.Session) TemporaryTopic(javax.jms.TemporaryTopic) ObjectName(javax.management.ObjectName)

Example 3 with TopicViewMBean

use of org.apache.activemq.broker.jmx.TopicViewMBean in project motech by motech.

the class MBeanService method getTopicStatistics.

/**
 * Returns topic statistics for the JMS topics.
 *
 * @return {@link List} of {@link TopicMBean}. One for each topic.
 */
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<TopicMBean> getTopicStatistics() {
    try {
        List<TopicMBean> topics = new ArrayList<>();
        for (ObjectName name : mBeanServer.getTopics()) {
            String destination = name.getKeyProperty(mBeanServer.getDestinationProperty());
            TopicViewMBean topicView = mBeanServer.getTopicViewMBean(name);
            TopicMBean topic = new TopicMBean(destination);
            topic.setEnqueueCount(topicView.getEnqueueCount());
            topic.setDequeueCount(topicView.getDequeueCount());
            topic.setExpiredCount(topicView.getExpiredCount());
            topic.setConsumerCount(topicView.getConsumerCount());
            topics.add(topic);
        }
        return topics;
    } catch (IOException ex) {
        throw new MotechException("Could not access MBeans ", ex);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) TopicViewMBean(org.apache.activemq.broker.jmx.TopicViewMBean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TopicMBean(org.motechproject.admin.domain.TopicMBean) ObjectName(javax.management.ObjectName) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ObjectName (javax.management.ObjectName)3 TopicViewMBean (org.apache.activemq.broker.jmx.TopicViewMBean)3 Connection (javax.jms.Connection)2 Session (javax.jms.Session)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 JMSSecurityException (javax.jms.JMSSecurityException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 TemporaryTopic (javax.jms.TemporaryTopic)1 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)1 TransportConnection (org.apache.activemq.broker.TransportConnection)1 DurableSubscriptionViewMBean (org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean)1 Test (org.junit.Test)1 TopicMBean (org.motechproject.admin.domain.TopicMBean)1 MotechException (org.motechproject.commons.api.MotechException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1