Mule Request Reply: Send Reply After All the Flow Processed

519 views Asked by At

currently I am working with mule. I have 3 flow: RequestFlow, ServiceResponse, and SendResponse.

Flow

On the first flow, I processed the request (transform the request parameter, write it into wmq, etc). FYI, wmq on this flow can only be used for write.

On the second flow, I read the response from server via another wmq, transform it into json, and send to VM. FYI, wmq on this flow only can be used for read.

On the third flow, I tried to send back the response to the first flow and generate a file.

To send back the response from flow 3 to flow 1, I try to use request-reply

But, unfortunately, when I tried to send a request, I found out that:

  1. After it reach request-reply component on the first flow, it will directly go to the third flow.
  2. And then, after mule processed all the operation on the third flow, it will send the response back to the request-reply component.
  3. Do some logging (logger component on first flow)
  4. Then, go to the flow, processed all the operation
  5. Processed the third flow again

That's why, after all the process has been finished, my application will:

  1. Generate 2 files (1 contain request xml and 1 contain json response)
  2. Return the request xml to http

However, It's not what I want. The flow that I need is:

  1. Mule processed the operation on first flow until the request-reply component
  2. Go to the second flow and processed all the component
  3. After it finish with second flow, it will goes to third flow. Proceed all the component
  4. Send the reply back to request-reply component on the first flow
  5. Do some logging (logger component in first flow)
  6. And finish

Result from this application should be:

  1. 1 File contain JSON response
  2. JSON Response on http

So, how to do so? Thanks in advance.

1

There are 1 answers

6
David Dossot On BEST ANSWER

You don't show the flow that consumes the messages sent to the sender path by the VM outbound endpoint in request-reply: I'm assuming it's a flow that takes care of sending the message to the server.

It seems that all you miss is an VM outbound endpoint in SendResponse that would send the message to the response path, onto which the VM inbound is waiting in the request-reply.

PS. Of course, it's assumed the the server propagates the JMS correlation ID from the request message to the response message, otherwise Mule (nor any client for that matter) could ever reconnect the response to the request and the request-reply would fail.

PPS. You don't need an all router around the single VM outbound endpoint in request-reply.