architecture for request/response
jkester Aug 6, 2003 3:36 AMHello,
I try to do the following:
A client calls a Stateless SessionBean QuoteService to make a quote. This stateless sessionbean looks up (with the help of some sessionbeans/entities) which companies are configured to make a quote. It wants to send to each of them a request, at the same time, and then merge the responses and send those back to the client.
From here I tried several approaches: the specific company services each in a separate sessionbean. The QuoteService starts a thread for each of them and collects the results. If some of them don't respond, the threads are cut off after a timeout. This approach failed. As I read as well, one shouldn't start threads inside a sessionbean. For one concurrent QuoteService call it all went well, but with several concurrent users at the same time, the new threads seemed to be waiting on each other/started sequentially instead of parallel-wise. Besides, suddenly the pooling to the other entity/session beans did not work any more. No threads thus.
Then I read on the forum that one should create Message Driven Beans for each specific company service to be called, and let the QuoteService start them by sending a message to each of them. That will work. But how do I get the results back? I tried to implement a response queue and let the sessionbean wait with receiver.receive. Only, I don't know how many results I will receive in the end and again have to cut off after a certain time.
Choosing the receiver.receive() method is dangerous. What if none comes back? And when I sent three messages, should I call receive three times?
Choosing receiver.receive(30000) would maximally wait 30 seconds. But here again I am introducing threads and as described above, with concurrent users this is not going to work. Besides how to get three messages returned?
QueueRequestor seems to be nothing else than a kind of helper class that also contains a receive method ...
So far I don't know how to let a sessionbean wait for a maximum time and let it receive all messages that are replies on its own originating outgoing messages ..
Maybe this can only be done on the client side? That would be a pity, as I would love to hide this functionality for clients.
So far I can only think of:
let quoteservice send messages to all companies, and then return a unique id and a number of messages back to the client.
Let the client wait for the response queue with a message selector using the unique id, and either retrieve all messages, or wait a maximum time.
I don't like this at all, much too mcuh functionality on client's side :-(.
Hope someone can steer me in the proper direction.
Regards, Jan