Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replay Messages sent over ActiveMQ

Tags:

java

activemq

Is there an easy way to create a copy of every message sent over a queue, so that if needed, the user could browse the list of previously transmitted messages and replay them numerous times with the click of a button?

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

like image 537
user1904583 Avatar asked Oct 06 '22 16:10

user1904583


1 Answers

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

First, you could setup copying of messages to a "copy queue". This has to be done once per queue with this strategy. Like this 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 a tool to browse through the messages on the COPY queue, and if needed, resend them to the OUT queue. I like the Hermes JMS tool for such things.

If you want something more fancy, you could read up on mirrored queues.

There is another rather simple way to achieve easy copy of all messages.

Use apache-camel that is bundled with activemq. This config inside camel.xml would achieve automatic copy of all messages to queues that begins with FOO.* This route would need some fixup of the copy queue name, but in priniple it works as a one time config for wiretapping.

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

A very important aspect here is that your server will fill up over time if you store all messages. I suggest you read up on ActiveMQ memory management or, just keep message copies for given timeframe. This can be automated in the sense that the sending system can actually set a message expiry so that messages get deleted automatically after a number of days/weeks/months.

like image 97
Petter Nordlander Avatar answered Oct 10 '22 04:10

Petter Nordlander