I am working on an architecture for a mq and j2ee based middleware environment. This environment is currently based on pure java applications, running separately, that produce and consume jms messages.
One peculiarity i am trying to address is this:
We have a component that produces jms messages, and sends them to a queue. These messages are required to build up until a certain time of day, when another component starts up, which consumes the messages - and the processing flows on from there.
Now, in the current way of doing things, a systems management tool would start this consuming component at the required time, and shut it down later.
I am trying to find an elegant way of fulfilling this requirement in a j2ee container.
Can we tell the appserver to suspend a bean? As these consumers will most likely all be MDB's, is there an appropriate way of doing this?
Probably a hacky way of doing this would be:
in the onMessage() method of the MDB, we could check an attribute somewhere that would indicate if we should be running. If we are, then process, else, ??rollback the message??
I don't like this approach at all!!
Has anyone had to do this, or does anyone have some suggestions? (Non-Appserver Specific a bonus)
Try a timer that regullary (once a day) reads messages from the queue and consumes them. However yoou should chek the your app. server JMS documentation on how long a message is kept in a queue before it times out and is dropped.
Best regards, Mircea
Sure, but how does this fit into the context of a J2EE container?
One of the prime directives of J2EE servers is that they manage the lifecycle of beans for us. In the case of MDB's, they determine how many instances should be created or pooled, and they feed messages from queues/topics directly to the bean instances.
If I want to ensure that these messages are only processed at a given time, i am going to need some help from the container, or implement the ugly check routine i referred to earlier.
What i'm looking for is a solution that tells the container not to start calling onMessage() until a certain time/condition is reached.
You would need a Timer if this is going to work internally. Either you have an appserver with EJB 2.1 with Timer implementation or use your app server propriatery Timer. The Timer can retrieve the messages and republish on a different topic on which MDBs are listening. The timer will have to start a durable subscriber to get all the messages.