You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by abdiels <ab...@gmail.com> on 2013/08/23 20:50:38 UTC

How to process a response and the original message after submitting to a component

When I post a message to a component which will give me a distinct out
message (like http, jdbc, etc.), what is the best way to continue processing
both the in and out messages in parallel? In other words, how can I send the
response message (out) on a separate thread while I continue the initial
route with the request message (in)?

The scenario we are trying to handle is as follows. We receive a customer
file, for which we generate several receipt reports which are sent back to
the customer. Those reports are to be sent back as soon as they are
generated while the original inbound file continues through the processing
cycle.

pseudo-route would look like this in theory:
From("file:")
.to("http:validateFileAndGenerateReceiptReport1")
.to("file:report1.txt")
.to("http:validateFileAndGenerateReceiptReport2")
.to("file:report2.txt)
.to(...further processing of inbound file")

Of course this does not work for the original inbound file data iss
overwritten with the first HTTP response which is not what we need.

I know we could just backup the inbound data into a temporary header
property before calling the HTTP components and then restore it into the
body later in the route before calling the second HTTP component but I was
wondering if there is a cleaner way to accomplish this.

We are planning on doing something like this unless you have a better
solution:

From("file:")
.setHeader(request, in.body)
.to("http:validateFileAndGenerateReceiptReport1")
.to("file:report1.txt")
.setBody(header(request))
.to("http:validateFileAndGenerateReceiptReport2")
.to("file:report2.txt)
.setBody(header(request))
.to(...further processing of inbound file")
 




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-process-a-response-and-the-original-message-after-submitting-to-a-component-tp5737841.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to process a response and the original message after submitting to a component

Posted by Christian Müller <ch...@gmail.com>.
A custom AggregationStrategy in the multicast will not work?
Otherwise you could use the enrich() DSL...

Best,
Christian
Am 23.08.2013 23:59 schrieb "abdiels" <ab...@gmail.com>:

> Christian,
>
>      Thank you for your reply; however, it is not that simple.  The message
> that will continue is dependent on the answer from the component.  So think
> about it this way, we send to some validation out of that we get a report
> with the results which needs to go to the client; however, some clients
> don't want to stop even if validation fails so the main message has to
> continue.  I hope you see that multicast will not work since the multicast
> will only get the "out" message from the previous component and not the
> original "in".  In my case I want to go to a component and after that
> component executes, I want to do something else with the message that went
> into that component and the message that resulted from that component.
>
> Thank you,
>
> Abdiel
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-process-a-response-and-the-original-message-after-submitting-to-a-component-tp5737841p5737845.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: How to process a response and the original message after submitting to a component

Posted by abdiels <ab...@gmail.com>.
Christian,

     Thank you for your reply; however, it is not that simple.  The message
that will continue is dependent on the answer from the component.  So think
about it this way, we send to some validation out of that we get a report
with the results which needs to go to the client; however, some clients
don't want to stop even if validation fails so the main message has to
continue.  I hope you see that multicast will not work since the multicast
will only get the "out" message from the previous component and not the
original "in".  In my case I want to go to a component and after that
component executes, I want to do something else with the message that went
into that component and the message that resulted from that component.

Thank you,

Abdiel



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-process-a-response-and-the-original-message-after-submitting-to-a-component-tp5737841p5737845.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to process a response and the original message after submitting to a component

Posted by Christian Müller <ch...@gmail.com>.
See http://camel.apache.org/multicast.html

Best,
Christian
Am 23.08.2013 20:51 schrieb "abdiels" <ab...@gmail.com>:

> When I post a message to a component which will give me a distinct out
> message (like http, jdbc, etc.), what is the best way to continue
> processing
> both the in and out messages in parallel? In other words, how can I send
> the
> response message (out) on a separate thread while I continue the initial
> route with the request message (in)?
>
> The scenario we are trying to handle is as follows. We receive a customer
> file, for which we generate several receipt reports which are sent back to
> the customer. Those reports are to be sent back as soon as they are
> generated while the original inbound file continues through the processing
> cycle.
>
> pseudo-route would look like this in theory:
> From("file:")
> .to("http:validateFileAndGenerateReceiptReport1")
> .to("file:report1.txt")
> .to("http:validateFileAndGenerateReceiptReport2")
> .to("file:report2.txt)
> .to(...further processing of inbound file")
>
> Of course this does not work for the original inbound file data iss
> overwritten with the first HTTP response which is not what we need.
>
> I know we could just backup the inbound data into a temporary header
> property before calling the HTTP components and then restore it into the
> body later in the route before calling the second HTTP component but I was
> wondering if there is a cleaner way to accomplish this.
>
> We are planning on doing something like this unless you have a better
> solution:
>
> From("file:")
> .setHeader(request, in.body)
> .to("http:validateFileAndGenerateReceiptReport1")
> .to("file:report1.txt")
> .setBody(header(request))
> .to("http:validateFileAndGenerateReceiptReport2")
> .to("file:report2.txt)
> .setBody(header(request))
> .to(...further processing of inbound file")
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-process-a-response-and-the-original-message-after-submitting-to-a-component-tp5737841.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>