Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Accessing MBeanServer from EJB

42 views
Skip to first unread message

Stephen Sill II

unread,
May 4, 2025, 12:02:25 PMMay 4
to WildFly
Hi, I have a question regarding querying jms-queue status, like number of messages in the queue, from an EJB so that I can display this info in a UI.

I've used jboss-cli to access this info previously but I've never tried to get at it from my deployed app.

As I understand it this meant to be done via JMX MBeanServer.

I searched this forurm and ran across a previous post that seemed to indicated this can be done via 
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer()

I currently have an application that runs in kubernetes in stand-alone mode but with full high-availability.   I specifically don't try to cluster the jms queue and instead whichever pod/node gets a request that uses jms, it processes it on that node.  This all works fine.  But the question arises in trying to query how many messages are in a queue,  how do I get a count  across 1-3 nodes/pods/replicas.  Does that require domain-mode?

Stephen Sill II

unread,
Jun 12, 2025, 8:28:20 AM (10 days ago) Jun 12
to WildFly
Just curious if anyone can answer this.

Basically.

Is it possible to get to get a combined  message count for a given JMS queue from each replica/node in a standalone HA cluster when jms on each is independent or would it require that activemq be configured for clustering as well, thus having some sort of shared storage?

Emmanuel Hugonnet

unread,
Jun 12, 2025, 9:24:43 AM (10 days ago) Jun 12
to Stephen Sill II, WildFly
Well you could use admin JMS messages to get the result I guess [1].
They even provide this example:

|ClientSession session = ... ClientRequestor requestor = new ClientRequestor(session, "activemq.management"); ClientMessage message =
session.createMessage(false); ManagementHelper.putAttribute(message, "queue.exampleQueue", "messageCount"); session.start(); ClientMessage
reply = requestor.request(m); int count = (Integer) ManagementHelper.getResult(reply); System.out.println("There are " + count + " messages
in exampleQueue");|


Emmanuel

[1]: https://activemq.apache.org/components/artemis/documentation/latest/management.html#using-management-message-api
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/wildfly/4ecfda4c-22b6-4345-bc25-1f043b7a879dn%40googlegroups.com
> <https://groups.google.com/d/msgid/wildfly/4ecfda4c-22b6-4345-bc25-1f043b7a879dn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Stephen Sill II

unread,
Jun 12, 2025, 9:52:18 AM (9 days ago) Jun 12
to WildFly
Interesting.

As it is now I have clustering enabled so that things like singleton ejb tasks will only run on one of the replicas.

So say I have a task that is configured to run every 5 min, and there are 3 replicas.  Every 5 min, one of the replicas will perform that task.  This works great.  In most of the cases that task simply fires and puts something on a queue so that if two of these happened they could be serialized to have one run after the other.

But I also have a case where a web service is called frequently and that webservice puts something on jms queue of whatever replica answered the request.  In my UI, which uses vaadin, I'm using sticky sessions so that the first pod/replicas that the user logged into remains the one they talk to via ui.   I'd like to, when an admin logs in, show the count of messages in the queue on each of the replicas.   But because the jms queue stuff is not configured for clustering, because as far as I understand it, it would require setting up some sort shared storage between the various replicas/pods,  I wasn't sure if I could ask the messaging system for counts in one place or if I would have to talk to each of the replicas to get their counts.

I'll take a look at your code and see how I might try this out.

Thanks!

Emmanuel Hugonnet

unread,
Jun 12, 2025, 10:53:59 AM (9 days ago) Jun 12
to Stephen Sill II, WildFly
Not super sure at what you are trying to achieve with your cluster (HA or horizontal scalability) so I won't delve into that but I think
this is more about pod going up/down and needing to access the data.
You need admin access on the management queue. Also the management queue name can be changed through the broker.xml iirc.
Regards,
Emmanuel
> <https://groups.google.com/d/msgid/wildfly/4ecfda4c-22b6-4345-bc25-1f043b7a879dn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/wildfly/23df0c37-0ae4-49b8-8499-fc1b85ba7b5en%40googlegroups.com
> <https://groups.google.com/d/msgid/wildfly/23df0c37-0ae4-49b8-8499-fc1b85ba7b5en%40googlegroups.com?utm_medium=email&utm_source=footer>.

Stephen Sill II

unread,
Jun 12, 2025, 11:17:10 AM (9 days ago) Jun 12
to WildFly
yeah it's more horizontal scalability than HA.   The use case I was thinking was an admin user is logged in to application UI, That session is tied, via sticky sessions, to a particular pod.  So the vaadin ui makes calls to the various ejbs via remote interface.   Those EJBs  in most cases are Stateless.  I'm looking to be able to expose a method like getMessageCount(String queueName) that would get the combined counts for queueName on each of the replicas.  The obvious way to accomplish what I'm wanting to do would be to host another pod that only does the activemq and have the replicas talk to that for doing jms.   My reason for not doing that at his point is cases like when GKE updates the cluster and nodepood and pods dynamical spin up and shutdown and join/leave the cluster.  I've not tackled trying actually cluster my activemq before.  I might need to read up on that.

The wildfly cluster is not in domain mode and I was curious if that would be necessary to do what I'm talking about.  I'll mess with it.  I have some other things that are much higher priority at the moment, but I was just curious since it would be nice if an admin could see if those queues are backing up for some reason.

Thanks,
Stephen

Reply all
Reply to author
Forward
0 new messages