Tuesday, 1 October 2013

Apache Camel - Issue a HTTP-Request from within a Processor

Apache Camel - Issue a HTTP-Request from within a Processor

a similar, but more general question has been asked here: Business logic
in Camel processors vs service endpoints.
Now consider the following flow, which I trigger with parameters (p,q):
Route: E1 -> E2
E1 itself issues an HTTP-request with parameters (p,q), receives the
response-data d (sync) and forwards this to E2, which continues processing
based on (p,q,d). So it essentially enriches the input with additional
data.
The endpoint, which is called contains the data that is to be integrated,
i.e. this will not change and needs not to be configurable in the future.
I tried two solutions, both of which seem kind of wrong to me:
use http4:url endpoints and piggyback the (p,q) in the header of the
messages (or alternatively properties of the exchange).
use a processor that explicitly/programmatically issues the http-request,
processes the response and forwards the expected (p,q,d). For convenience,
I did this with a producerTemplate being sent to http4:url inside the
camel-context.
Problem with the first is that it adds a lot of boilerplate procducers etc
and make the actual route really obscure. The second approach allows to
offload processing into a new class (and not mix it into the routes) but
still requires the camel-context and depends on this.
What the recomendation for this. I couldn't find anything around except
more abstract statements like "do not mix business logic with wiring" etc.
thanks, markus

No comments:

Post a Comment