This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes MDB with  MessageConsumers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDB with  MessageConsumers" Watch "MDB with  MessageConsumers" New topic
Author

MDB with MessageConsumers

Blue Rider Abc Murnau
Greenhorn

Joined: Aug 02, 2006
Posts: 4
Hi all,
Within an MDB I'm trying to resend a received Message to
second MDB and wait for a response (using a MessageConsumer).

I'm doing this inside the body of the onMessage() method of the first MDB.
There, a Temporary Queue is created and attached to the Message using
setJMSReplyTo(). This TQueue will be used by the second MDB to return
the answer back to the first MDB.

Has anybody tried this mechanism between MDB and worked ok? In my case
it is failing; basically the original source of the message times out
waiting for a response.

I wonder if the MDB's life-cycle prevents it from sending and then
waiting for a response.

Cheers.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9962
    
163

Havent tried this specific scenario before. Are you using transacted connection factory to send the message to the second MDB from the first MDB? Also, does the control ever reach the onMessage method of the second MDB? If it doesnt reach then i guess because the transaction of your onMessage method in 1st MDB is not yet committed, the message is never really sent to the queue and hence the second MDB is never invoked(i am assuming that you are using transacted connection factory)


[My Blog] [JavaRanch Journal]
Blue Rider Abc Murnau
Greenhorn

Joined: Aug 02, 2006
Posts: 4
Thanks Jaikiran,

I think the problem lies in that the message is not effectively sent to
the Queue until onMessage() has finished in the 1st MDB. This would prevent
this MDB to have a consumer waiting for a response inside this method.

The pseudo-code of what I was trying to do is:
onMessage(Message myMsg){
1.- CREATE TEMPORARY QUEUE AND USE IT IN myMsg.setJMSReplyTo()
2.- SEND myMsg TO 2nd MDB
3.- CONSUMER.RECEIVE(TIMEOUT_MILLIS) // wait for a response from 2nd MDB
4.- DONE
}

I don't think now that a message can be sent and then wait for a
response in the same onMessage body. The consumer is effectively blocking
the execution of onMessage().

What do you think?

Cheers
BR
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9962
    
163

One solution might be to have Bean Managed Transaction on your MDB. So your code in the onMessage would look like:



Effectively, after sending the message to the queue for 2nd MDB to pickup, you are committing the transaction and as a result the message will be delivered to MDB2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB with MessageConsumers
 
Similar Threads
How to stop MDB retry invocation during System Exception
Help??(Can we use wait method in Bean Class)
Error deserializing Object
Questions on MDB
MDB and BMT