a MessageSelector is a great idea (I never thought about this possibility before), but I forgot to mention: We will use different queues for the old and the new messages (I cannot tell you the reason at the moment, but this is a requirement). So I think, a selector does not make any sense, the request messages will be send to two different queues. Also I would have to check if we can change the old MDB and add a message selector to the old message - I dont think so :-(
We want to reuse as much code as possible (dont repeat yourself principle), otherwise we could simple write a new MDB which does everything the old MDB does plus the new pre- and postprocessing.
then forwarding the message to the old MDB, waiting for the response from the old MDB, doing postprocessing and then sending the response to the response queue.
Why dont you simply write a pojo (backed by an interface to determine lifecycle methods) and pass the Message to the methods of these pojos to do the actual work? That way you would have common functionality abstracted out to methods of this pojo ensuring reusability.
We have in fact something similar in our application. We call them MessageProcessors and we invoke the lifecycle methods of these processors for different kind of messages. The MDBs then basically act as Controllers. They receive the messages and invoke the processors to do the actual work.
That does sound like additional overhead. As far as I know, it is perfectly valid to use multiple queues to do part message processing - a process and forward paradigm. But forwarding to another MDB just for part processing may be bad from a performance point especially when you could just use plain old java abstraction.
You mean: Write PreprocessorABC.java and PostProcessorXYZ.java which offer the needed methods with the message as parameter, and then simply call these methods within the onMessage() of the MDB?
This sounds good, but therefore the logic of the old MDB must also be move to such a POJO e.g. Calculator.java, right?
Then old MDB would use only Calculator.java, the new MDB would use all three POJOs, right?
Well, how would you realize process and forward with multiple queues then? You either have to use a MDB or the JMS API with receive() or onMessage(), dont you?