Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Calling an asynchronous web service & waiting for a response

$
0
0
I need to use an asynchronous web service from within a route. By asynch I
mean that the remote service will respond immediately to the HTTP request
with an acknowledgement, but the result of the request will be sent later
to an incoming web service.

I have implemented this via the Request-Reply EIP implemented for JMS, but
I was hoping for a mechanism with less moving parts. I've included routes
to demonstrate the problem my solution.

Is there a more elegant solution?

Paul

<camelContext trace="false" xmlns="
http://camel.apache.org/schema/spring">
<!-- client server web services, with an asynchronous
server. We use JMS
to utilise the Request Response EIP (which as far as I
can see) can't
be utilised explicitly to wrap http - perhaps as it
is inherently request-response anyway).
Looks like SOAP handles this via WS-Addressing with
the ReplyTo header

<route id="asynch client">
<from uri="jetty:http://localhost:8888/asynchclient"/>
<setHeader
headerName="JMSCorrelationID"><simple>${headers.data}</simple></setHeader>
<to
uri="jms:queue:asynchclient?exchangePattern=InOut橪;replyTo=asynchClientCallback"/>
<log message="Got Response from asynch server"/>

</route>

<route id="asynch client requester">
<from uri="jms:queue:asynchclient?disableReplyTo=true"/>
<to uri="jetty:
http://localhost:8889/asynchserver?bridgeEndpoint=true" />
</route>

<route id="asynch client reciever">
<from uri="jetty:http://localhost:8888/asynchcallback
"/>
<setHeader
headerName="JMSCorrelationID"><simple>${headers.data}</simple></setHeader>
<inOnly uri="jms:queue:asynchClientCallback"/>
</route>

<route id="asynch server ack">
<from uri="jetty:http://localhost:8889/asynchserver"/>
<wireTap uri="direct:sendResponse"/>
<setBody><simple>OK</simple></setBody>
</route>

<route id="asynch server response">
<from uri="direct:sendResponse"/>
<delay><constant>10000</constant></delay>
<setBody><simple>{"data": ${headers.data}, "result":
"Some response for ${headers.data}"}</simple></setBody>
<setHeader
headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<to uri="jetty:
http://localhost:8888/asynchcallback?bridgeEndpoint=true"/>
</route>
</camelContext>

Viewing all articles
Browse latest Browse all 5648

Trending Articles