JMS Request/Response with Timeout


EJB design: JMS Request/Response with Timeout

  1. JMS Request/Response with Timeout (2 messages)

    Hi everyone,

       I am hoping someone can help me out with this :). Thanks in advance!

       The scenario is like this. Client call EJB method. Inside the method one of the task is to make a connection to a external server to process and get some data.

       As the external server processing might take very long to complete, I need to be able to timeout the client. And if the external server reply after the timeout, I need to inform it to rollback the processing.

       I am thinking of doing it with a JMS request/response. Client call EJB, EJB send a JMS message to Queue (Q1), with TemporaryQueue (TQ2) as the reply channel. EJB then receives on TQ2 with a timeout setting. MDB picks up the message in Q1 and goes off to do it processing and at a later point in time send the result back using TQ2.

       The problem here is since the EJB is the one controlling the timeout. How does EJB inform MDB that it has already timeout so that MDB can do the necessary rollback processing ?

       I was thinking of deleting TQ2 immediately after the receive returns so that MDB will have a exception when it tries to write to TQ2.

       However, this might result in 1) EJB timeout, 2) MDB send to TQ2, 3) EJB delete TQ2 without knowing there is a message. 4) MDB doesn't know that EJB has timeout.

       Anyone can give me some suggestions ?

       p.s. Sorry for such a long posting :P
  2. JMS Request/Response with Timeout[ Go to top ]

    Just use a Requestor object which behaves like the QueueRequestor in the javax.jmx namespace but allows a timeout to be specified. Then if you don't receive a reply in the correct amount of time you can throw an exception to force the MDB to rollback.

    e.g. ActiveMQ has a helper Requestor to do exactly this; though its quite trivial to create your own...
  3. JMS Request/Response with Timeout[ Go to top ]

    Hi James,

       Thanks for the reply. I think this will work just fine.

    Best Regards