Play messages sent via ActiveMQ

Is there an easy way to create a copy of each message sent in turn so that, if necessary, the user can view a list of previously transmitted messages and play them several times with the click of a button?

I have program X that sends a message to the queue, and program Y then reads it. I would like to be able to play back the message that was sent earlier, without having to go back to program X and regenerate it again.

+4
source share
2 answers

There are easy ways to get started if you have too many messages or too many queues.

First, you can configure message copying to the “copy queue”. This strategy must be run once in a queue. How is it in activemq.xml

  <destinationInterceptors> <virtualDestinationInterceptor> <virtualDestinations> <compositeQueue name="INVOICE.OUT"> <forwardTo> <queue physicalName="INVOICE.IN" /> <queue physicalName="INVOICE.COPY" /> </forwardTo> </compositeQueue> </virtualDestinations> </virtualDestinationInterceptor> </destinationInterceptors> 

Then use the tool to view messages in the COPY queue, and send them to the OUT queue if necessary. I like the Hermes JMS tool for such things.

If you need something more interesting, you can read mirrored queues .

There is another fairly simple way to achieve a simple copy of all messages.

Use apache-camel, which is associated with activemq. This configuration inside camel.xml will provide an automatic copy of all messages in the queue starting with FOO. * For this route, some correction of the name of the copy queue will be required, but in principle, it works as a one-time configuration for listening.

 <route> <from uri="activemq:FOO.>"/> <setHeader headerName="CamelJMSDestination"> <simple>COPY.${header.JMSDestination}</simple> </setHeader> <to uri="activemq:dummy"/> </route> 

A very important aspect is that your server will fill up over time if you save all messages. I suggest you read ActiveMQ Memory Management or just save a copy of messages for a given time frame. This can be automated in the sense that the sending system can indeed set the expiration date of the message so that messages are automatically deleted after a few days / weeks / months.

+3
source

It’s not easy, I’m afraid, because such behavior can lead to a violation of the idea of ​​a queuing system. However, there are some things you can try:

  • It's a bit hacky: send messages to a reliable queue (and make sure the messages are strong yourself) and turn off automatic confirmation. If you do not acknowledge any message, the server will save them and you can use QueueBrowser to access them. However, they will eventually time out
  • Keep a copy of each message when it reaches program Y. In fact, you just need to save the link to make sure the messages are not garbage collected. Depending on the speed of your message and available memory, you will have to clear messages in the end.
  • Create an ActiveMQ plugin. This is definitely the hardest and most difficult of the three. You will create a plugin (see ActiveMQ documentation on how to create them) and intercept the message in the send() or preDispatch() plugin methods. There you keep a copy of the content . You will also have to listen to playback requests and send history on demand (you can use the response field in the JMS message headers). The statistics plugin that ships with ActiveMQ is a good source to get started here. Oh, and of course your server will also run out of memory.
0
source

All Articles