1

I'm building a simple message delegation application. Messages are being send on both ends via JMS. I'm using a MDB to process incoming messages, transform them and send them to a target queue. Unfortunately the same messages can be send to the incoming queue more than once but it is not allowed to forward duplicates.

So what is the best way to accomplish that?

Since there can be multiple MDBs listening on the incoming queue a need a single cache where I can store the unique message uuids of the incoming messages for at least an hour. How should this cache be accessed? Via a singleton/ static class (I'm running Java EE 5 and thus don't have the singleton annotation)?

In addition I think all operations must be synchronized, right? Does that harm performance too much?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Leikingo
  • 890
  • 3
  • 10
  • 23

1 Answers1

2

@Ingo: are you OK with database solution. You can full fledged DB server or simple apache derby solution for this.. If so, you can have a simple table where you can store message unique UId and can check against it for uniqueness....this solution will have following benefits:

  1. Simple code
  2. No need of time bound cache(1 hour). You can check for uniqueness of a message forever.
  3. Persistent record of what messages came in.
  4. No need of expensive synchronized, you can rely on DB isolation level to have consistency.
  5. centralized solution for your possibly many deployments of application.
ag112
  • 5,537
  • 2
  • 23
  • 42
  • Hi and thanks for the quick response. I agree for most of your benefits but I think using a db solution is a bit over the top for "simply" caching some strings. In addition I would still need an additional job to expire the keys and clean up the table cause I don't need a long time protocol of incoming msgs. Regarding the synchronization: I think the DB just hides this. But nevertheless, I will propose your suggestion. After a bit of more reading, what about ehcache? – Leikingo Jul 15 '11 at 08:00