How to write custom logs when message is enqueued & dequeued in ActiveMQ

Viewed 494

When I enqueue/dequeue message ActiveMQ writes a log in <ACTIVEMQ_HOME>/data/activemq.log

2020-03-03 12:59:36,505 |  test001              | DEBUG | queue://test001, subscriptions=0, memory=0%, size=172, pending=0 toPageIn: 0, force:false, Inflight: 0, pagedInMessages.size 172, pagedInPendingDispatch.size 172, enqueueCount: 200, dequeueCount: 28, memUsage:178980, maxPageSize:200 | org.apache.activemq.broker.region.Queue | ActiveMQ BrokerService[localhost] Task-23

If I send one message to ActiveMQ, lets say "Test", I want to write publisher name(hostname) message in log file. Also if I have multiple consumer (e.g. consumer1, consumer2, etc.) then I want to write consumer name(hostname) in the log file when it dequeues a message.

1 Answers

It still unclear exactly what you are trying to achieve here but close as I can guess is you want something along the lines of a custom Logging Broker Plugin. From the vague information you've given on what you want to log and where this seems like the best option. A broker plugin gives you access to messages entering and exiting broker queues and as such you could log whatever information you find is useful to your use case.

Related