You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Paul McCulloch <pk...@gmail.com> on 2014/07/31 14:46:41 UTC
Calling an asynchronous web service & waiting for a response
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>
Re: Calling an asynchronous web service & waiting for a response
Posted by Paul McCulloch <pk...@gmail.com>.
This isn't SOAP - just plain HTTP. So, there no WS-Addressing - just a
plain callback to a URL that the remote system is pre-conffigured to use.
On 31 July 2014 13:48, Matt Sicker <bo...@gmail.com> wrote:
> Are you using WS-Addressing or is this an HTTP callback?
>
>
> On 31 July 2014 07:46, Paul McCulloch <pk...@gmail.com> wrote:
>
> > 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>
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
Re: Calling an asynchronous web service & waiting for a response
Posted by Matt Sicker <bo...@gmail.com>.
Are you using WS-Addressing or is this an HTTP callback?
On 31 July 2014 07:46, Paul McCulloch <pk...@gmail.com> wrote:
> 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>
>
--
Matt Sicker <bo...@gmail.com>