Discussion:
JAVA ActiveMQ JMX browse messages on Topic
Hitesh
2017-08-18 16:24:10 UTC
Permalink
Hi all,

The following question is for ActiveMQ 5.13.

I have 2 durable subscribers listening to a topic, lets say ExampleTopic.
I need to delete all the messages on that topic when a particular event
occurs. I tried to find the jolokia apis to do the same but couldn't find
any.
So I've decided to use JMX Mbeans to browse the messages and delete them one
by one.

A simple java program which will connect to JMXService and fetch the
information for all the messages.

JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
TopicViewMBean bean = MBeanServerInvocationHandler.newProxyInstance(conn,
mbeanName, TopicViewMBean.class, true);
List list = bean.browseMessages();

However this throws the following exception:

java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy0.browseMessages(Unknown Source)
at com.exportstaging.main.Test.main(Test.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: javax.management.ReflectionException: No such operation:
browseMessages


I tried to find the web for this, but couldn't find any solution.

Can someone help me fix this.

Thanks in advance




--
View this message in context: http://activemq.2283324.n4.nabble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-tp4729813.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Tim Bain
2017-08-19 02:01:30 UTC
Permalink
You can browse queues, but not topics.

Tim
Post by Hitesh
Hi all,
The following question is for ActiveMQ 5.13.
I have 2 durable subscribers listening to a topic, lets say ExampleTopic.
I need to delete all the messages on that topic when a particular event
occurs. I tried to find the jolokia apis to do the same but couldn't find
any.
So I've decided to use JMX Mbeans to browse the messages and delete them one
by one.
A simple java program which will connect to JMXService and fetch the
information for all the messages.
JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
TopicViewMBean bean = MBeanServerInvocationHandler.newProxyInstance(conn,
mbeanName, TopicViewMBean.class, true);
List list = bean.browseMessages();
java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy0.browseMessages(Unknown Source)
at com.exportstaging.main.Test.main(Test.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(
AppMain.java:147)
browseMessages
I tried to find the web for this, but couldn't find any solution.
Can someone help me fix this.
Thanks in advance
--
View this message in context: http://activemq.2283324.n4.
nabble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-tp4729813.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Tim Bain
2017-08-19 04:23:17 UTC
Permalink
By the way, there's an ongoing thread (
http://activemq.2283324.n4.nabble.com/Delete-Purge-Topic-tp4728932.html)
about whether it's possible to use the JMX delete action on the topic to
effectively purge the existing messages from the topic. I'd be curious
whether you hit the same issues that that thread's OP does when trying that
approach.

Tim
Post by Tim Bain
You can browse queues, but not topics.
Tim
Post by Hitesh
Hi all,
The following question is for ActiveMQ 5.13.
I have 2 durable subscribers listening to a topic, lets say ExampleTopic.
I need to delete all the messages on that topic when a particular event
occurs. I tried to find the jolokia apis to do the same but couldn't find
any.
So I've decided to use JMX Mbeans to browse the messages and delete them one
by one.
A simple java program which will connect to JMXService and fetch the
information for all the messages.
JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
TopicViewMBean bean = MBeanServerInvocationHandler.newProxyInstance(conn,
mbeanName, TopicViewMBean.class, true);
List list = bean.browseMessages();
java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy0.browseMessages(Unknown Source)
at com.exportstaging.main.Test.main(Test.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
ssorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.
java:147)
browseMessages
I tried to find the web for this, but couldn't find any solution.
Can someone help me fix this.
Thanks in advance
--
View this message in context: http://activemq.2283324.n4.nab
ble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-tp4729813.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Hitesh
2017-08-21 09:58:58 UTC
Permalink
Hey Tim,

Thanks for the reply.

I connected the MBeans using jconsole and found that it is possible to
browseMessages().
All the data that I've sent to that topic is accessible on JMX UI.
Following is the screenshot to verify the same.

<Loading Image...>


If this is possible to do via Jconsole UI, I believe it is also possible to
do it via JMXServices java APIs.
Can you quickly try the example I've posted and help me out if its not much
of a trouble?
Also a small modifications in the sample code which i provided,

List list = bean.browseMessages();
changes to
CompositeData[] list = bean.browse();

Thanks in advance



--
View this message in context: http://activemq.2283324.n4.nabble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-tp4729813p4729857.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Tim Bain
2017-08-22 06:09:40 UTC
Permalink
You're right and I was wrong: it is indeed possible to browse a topic. I
learned something new today; thanks.

It looks to me like your problem may be that you don't have the right
ObjectName. What you wrote appears to be for the broker, not for the topic.
I'd expect something more like this:

ObjectName topicViewMBeanName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Topic,destinationName="
+ name);
Post by Hitesh
Hey Tim,
Thanks for the reply.
I connected the MBeans using jconsole and found that it is possible to
browseMessages().
All the data that I've sent to that topic is accessible on JMX UI.
Following is the screenshot to verify the same.
<http://activemq.2283324.n4.nabble.com/file/n4729857/Browse_Messages.png>
If this is possible to do via Jconsole UI, I believe it is also possible to
do it via JMXServices java APIs.
Can you quickly try the example I've posted and help me out if its not much
of a trouble?
Also a small modifications in the sample code which i provided,
List list = bean.browseMessages();
changes to
CompositeData[] list = bean.browse();
Thanks in advance
--
View this message in context: http://activemq.2283324.n4.
nabble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-
tp4729813p4729857.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Hitesh
2017-08-22 13:54:54 UTC
Permalink
Hi Tim,

You are right, after providing the topic information, I was able to browse
the messages and call the removeMessage(String JMSMessageID) on them.

However, On recursive testing, I found after few iterations the
removeMessage won't work and the message is not deleted from the topic.

Following is the code to delete the messages:

MBeanServerConnection conn = JMXConnectorFactory.connect(new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi")).getMBeanServerConnection();
ObjectName broker = new
ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
BrokerViewMBean brokerViewMBean =
MBeanServerInvocationHandler.newProxyInstance(conn, broker,
BrokerViewMBean.class, true);
for (ObjectName topics : brokerViewMBean.getTopics()) {
if (topics.getKeyProperty("destinationName").equals("TestTopic")) {
TopicViewMBean topicViewMBean =
MBeanServerInvocationHandler.newProxyInstance(conn, topics,
TopicViewMBean.class, true);
for (ObjectName name : topicViewMBean.getSubscriptions()) {
DurableSubscriptionViewMBean viewMBean =
MBeanServerInvocationHandler.newProxyInstance(conn, name,
DurableSubscriptionViewMBean.class, true);
for (CompositeData data : viewMBean.browse()) {
viewMBean.removeMessage((String) data.get("JMSMessageID"));
}
}
}
}


After removeMessages, if I do getPendingQueueSize(), I still find it to be
the same as it was before delete.
I even did a recursive check till the pending count is not 0, but still it
wont work.
Do you think there's any configuration which might cause this behavior?
I feel this code should do the trick, but still somewhere something is
missing and I can't figure out what...



--
View this message in context: http://activemq.2283324.n4.nabble.com/JAVA-ActiveMQ-JMX-browse-messages-on-Topic-tp4729813p4729893.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Raffi
2017-08-30 02:33:00 UTC
Permalink
Is it safe to use JMX-based message browsing for queues when troubleshooting
production issues?



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Clebert Suconic
2017-09-03 21:35:28 UTC
Permalink
It depends on what is the issue.

If the broker is suffering performance issues browsing messages may
aggravate the problem. As you will also be competing for resources.


I would monitor message counts. Consumer counts and other measures like
that.
Post by Raffi
Is it safe to use JMX-based message browsing for queues when
troubleshooting
production issues?
--
http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
--
Clebert Suconic
Raffi
2017-09-04 14:48:03 UTC
Permalink
That's a good point, competing with resources, ty.



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Loading...