Ammar
Ammar

Reputation: 5620

How can we save Java Message Queues for reference?

How can we keep track of every message that gets into our Java Message Queue? We need to save the message for later reference. We already log it into an application log (log4j) but we need to query them later.

Upvotes: 0

Views: 489

Answers (5)

Pascal Thivent
Pascal Thivent

Reputation: 570365

I implemented such a solution in the past, we chose to store messages with all their characteristics in a database and developed a search, replay and cancel application on top of it. This is the Message Store pattern:

alt text
(source: eaipatterns.com)

We also used this application for the Dead Letter Channel.

alt text
(source: eaipatterns.com)

If you don't want to build a custom solution, have a look at the ReplayService for JMS from CodeStreet.

Upvotes: 1

Joe Zitzelberger
Joe Zitzelberger

Reputation: 4263

The best way to do this is to use whatever tracing facility your middleware provider offers. Or possibly, you could set up an intermediate listener whose only job was to log messages and forward on to your existing application.

In most cases, you will find that the middleware provider already has the ability to do this for you with no changes or awareness by your application.

Upvotes: 0

crowne
crowne

Reputation: 8534

I would change the queue to a topic, and then keep the original consumer that processes the messages, and add another consumer for auditing the messages to a database.

Some JMS providers cater for topic-to-queue-bridge definitions, the consumers then receive from their own dedicated queues, and don't have to read past messages that are left on the queue due to other consumers being inactive.

Alternatively, you could write a log4j appender, which writes your logged messages to a database.

Upvotes: 0

rsp
rsp

Reputation: 23373

You could create a database logging table for the messages, storing the message as is in a BLOB column, the timestamp that it was created / posted to the MQ and a simple counter as primary key. You can also add fields like message type etc if you want to create statistical reports on messages sent.

Cleanup of the tabe can be done simply by deleting all message older than the retention period by using the timestamp column.

Upvotes: 1

Bozho
Bozho

Reputation: 597106

You can store them

  • in memory - in a collection or in an in-memory database
  • in a standalone database

Upvotes: 2

Related Questions