camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nestor Urquiza <nestor.urqu...@gmail.com>
Subject Re: Best practice to parse JSON response and retry if error
Date Tue, 22 May 2012 21:33:51 GMT
Thank you guys! That did the trick.

Using a direct route with noErrorHandler() encapsulating all the logic and
calling it from the route that will perform the retries works as expected.
<code>
        from("seda:queue.sample")
        .errorHandler(defaultErrorHandler()
                .log(log)
                .maximumRedeliveries(5)
                .backOffMultiplier(2)
                .useExponentialBackOff()
                .redeliveryDelay(1000)
                .maximumRedeliveryDelay(10000)
                .retryAttemptedLogLevel(LoggingLevel.WARN))
        .to("direct:direct.sample");
                
        from("direct:direct.sample")
        .errorHandler(noErrorHandler()) 
        .log(LoggingLevel.DEBUG, LOG_NAME, "Received message in queue
sample: id = ${id}")
        .to("http://localhost:8088/?cmd=ls%20/tmp/unlock")
        .unmarshal().json(JsonLibrary.Jackson, ShellResponse.class)
        .process(new ShellProcessor())
</code>

The disadvantage is that in a chained Services process (Service
Orchestration) several routes will be needed just to accomplish retries per
each service that fails.

I think for Service Orchestration I rather try to use a bean that invokes
each http service, analyze the response and throws Exception if error. That
way we need only one route which looks cleaner to me:
<code>
from("seda:queue.sample")
.setHeader("url",
constant("http://localhost:8088/?cmd=runFirstService")).bean(ShellBeanService.class)
.setHeader("url",
constant("http://localhost:8088/?cmd=runSecondService")).bean(ShellBeanService.class)
.setHeader("url",
constant("http://localhost:8088/?cmd=runThirdService")).bean(ShellBeanService.class);
</code>


Cheers,
- Nestor


--
View this message in context: http://camel.465427.n5.nabble.com/Best-practice-to-parse-JSON-response-and-retry-if-error-tp5711530p5713360.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message