user1493140
user1493140

Reputation: 6186

Mule 3 async-reply

I have a flow where I receive request via webservice. I forward that request to a JMS queue using component binding. However, I would like to get async-reply from that queue and use it as response to the webservice. Do I need to use reply-to and async-reply-router in the flow? Or is there any other way to do that in Mule 3? Any pointers?

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.pennmutual.services.mvi.MVIServiceImpl">
        <binding interface="com.pennmutual.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" />
        </binding>
            </component>

            <async-reply>

            </async-reply>

      </flow>

============ EDITED - SEE BELOW FOR RE-FRAMED QUESTION =================

I think I haven't done a good job in describing the scenario. Let me try again. Here's the scenario --

  1. A client calls our service described in this flow "mviService". mviService gets XML request via HTTP/SOAP based inbound endpoint. Let's call this request as XML121Request.4
  2. A component defined in MVI "com.xyz.services.mvi.MVIServiceImpl" makes some changes in XML121Request.
  3. Forwards this XML121 to a JMS queue "mviq.121.order". It uses component binding for this.
  4. The outbound endpoint to this JMS queue is a third party web service where this request is forwarded. The third party acknowledges the receipt of XML121 and the synchronous web service call returns.
  5. The response from that third party service comes at a later point of time, which is generally couple of seconds. The response comes asynchronously. Third party invokes another webservice endpoint on MVI and sends the XML121Response.
  6. MVI puts this response in a JMS queue named "mviq.async.service.reply".
  7. The "mviService" flow needs to wait for this response and send this response (after some modification) to caller(in step 1).

I'm able to get the response from third party and this response is enqued in a queue named "mviq.async.service.reply". I would like to use/consume this message and return it as a response to first call to MVI.

I'm trying to use "request-reply".

    <request-reply timeout="60000">
        <vm:outbound-endpoint path="request" />
        <jms:inbound-endpoint queue="mviq.async.service.reply"
            exchange-pattern="one-way" />
    </request-reply>

THe problem is that even though I don't want to have outbound-endpoint in this case, I still have to put one as this is required by request-reply tag. The flow waits for 60 seconds at that point of time but even if I put something in the queue "mviq.async.service.reply" the correlation ID doesn't match so the service timesout and returns an error.

flow is mentioned below.

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.pennmutual.services.mvi.MVIServiceImpl">
        <binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" />
        </binding>
    </component>

    <!-- <logger message="XML Correlation ID 1 is #[mule:message.headers(all)]" /> -->
    <request-reply timeout="60000">
        <vm:outbound-endpoint path="request" /> <!-- we don't care about this -->
        <jms:inbound-endpoint queue="mviq.async.service.reply"
            exchange-pattern="one-way" />
    </request-reply>
        <!-- <component class="com.xyz.mvi.CreateMVIServiceResponse"/> -->
</flow>

===== FLow with REPLY TO =============

<flow name="mviService">
    <http:inbound-endpoint address="http://localhost:62005/mvi"
        exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
    </http:inbound-endpoint>
    <component class="com.xyz.services.mvi.MVIServiceImpl">
        <binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
            method="process121Order">
            <jms:outbound-endpoint queue="mviq.121.order" exchange-pattern="request-response">
                <message-properties-transformer scope="outbound">
                    <add-message-property key="MULE_REPLYTO" value="mviq.async.service.reply" />
                </message-properties-transformer>
            </jms:outbound-endpoint>
        </binding>
     </component>
</flow>

Upvotes: 2

Views: 2471

Answers (1)

David Dossot
David Dossot

Reputation: 33413

I'd like to suggest you do not create a service component class and instead use cxf:proxy-service, which will give you direct access to the SOAP envelope and the opportunity to assemble the response the way you want at XML level.

This will free you from the constraint a service component class imposes on you, hence waive the need to use bindings and open the door to using request-response.

See this SO answer and check the (skinny) proxy service user guide for more information.

Upvotes: 2

Related Questions