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;
}
}));
}
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) {
}
}
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);
}
}
Aggregations