How to access the ActiveMQ "Classic" statistics plugin in Python
Question:
I referred to the ActiveMQ "Classic" documentation to get statistics of broker/queues and create some analysis based on the statistics. I am not able to fetch the stats with following code snippet.
Code snippet::
self.conn = stomp.Connection([('localhost', 61616)] , keepalive=True, try_loopback_connect=True, reconnect_attempts_max=3,)
self.conn.set_listener("testlistener", TestListener(print_to_log=True))
# couple of more listeners for some existing purpose
def retrieve_stats(self) -> None:
print("*************START*****************n")
self.conn.subscribe(destination="/queue/test") # created a new queue where stats can be pushed
self.conn.send(
body="",
destination="/queue/ActiveMQ.Statistics.Broker",
content_type="text/blah",
headers={
"amq-msg-type": "text",
"persistent": "true",
"reply-to": "/queue/test",
},
)
broker_stat_listener = self.conn.get_listener("testlistener").get_latest_message()
print(broker_stat_listener.__str__())
print("*************END*****************n")
Answers:
Generally, Python is using STOMP protocol. Simply setup the statistics broker plugin on the server-side, then send the messages to the specially named queues, and subscribe to the response queues to get the output.
I referred to the ActiveMQ "Classic" documentation to get statistics of broker/queues and create some analysis based on the statistics. I am not able to fetch the stats with following code snippet.
Code snippet::
self.conn = stomp.Connection([('localhost', 61616)] , keepalive=True, try_loopback_connect=True, reconnect_attempts_max=3,)
self.conn.set_listener("testlistener", TestListener(print_to_log=True))
# couple of more listeners for some existing purpose
def retrieve_stats(self) -> None:
print("*************START*****************n")
self.conn.subscribe(destination="/queue/test") # created a new queue where stats can be pushed
self.conn.send(
body="",
destination="/queue/ActiveMQ.Statistics.Broker",
content_type="text/blah",
headers={
"amq-msg-type": "text",
"persistent": "true",
"reply-to": "/queue/test",
},
)
broker_stat_listener = self.conn.get_listener("testlistener").get_latest_message()
print(broker_stat_listener.__str__())
print("*************END*****************n")
Generally, Python is using STOMP protocol. Simply setup the statistics broker plugin on the server-side, then send the messages to the specially named queues, and subscribe to the response queues to get the output.