Thanks for the suggestion. I tried it and noted that only parameters from
exchange outside the saga scope can be mapped using options. Is there any
way I can get an exchange object which failed inside the saga scope?

Cheers
Reji

On Tue, Sep 8, 2020 at 4:38 PM Alex Dettinger <[email protected]> wrote:

> Hi Reji,
>
>   I've never tested but it remind me about option:
>
> https://camel.apache.org/components/latest/eips/saga-eip.html#_using_custom_identifiers_and_options
>
> hth,
> Alex
>
> On Tue, Sep 8, 2020 at 9:48 PM Reji Mathews <[email protected]> wrote:
>
> > Hello community
> >
> > I was wondering if there is a way to retain the exchange data from the
> > point of failure in a Saga EIP. Find the following route
> > I have simulated an error right after parsing data from the create-order
> > api. I need to use the same in compensation flow to undo the order
> > creation.
> > Logs show that the value of header orderId never trickled down to
> > compensation flow.
> >
> > from("jetty:http://0.0.0.0:8081/testtxn?httpMethodRestrict=GET
> > ").streamCaching()
> >         .log("received http trigger")
> >
> >
> .saga().compensation("direct:rollback").propagation(SagaPropagation.REQUIRES_NEW)
> >             .log("creating fresh order")
> >             .setBody(constant("{ \"item_code\" : \"XAH504004\",
> > \"item_qty\" : 10 }"))
> >             .setHeader(Exchange.CONTENT_TYPE,
> constant("application/json"))
> >             .setHeader(Exchange.HTTP_METHOD, constant("POST"))
> >             .setHeader(Exchange.HTTP_URI,
> > constant("http://localhost:8000/orders";))
> >             .to("http:dummyhost")
> >             .log("order api response ${body}")
> >             .setHeader("orderId", jsonpath("$.businessObject.order_id"))
> >             .throwException(new Exception("This is a simulated
> > error")) // simulating a failure
> >             .end();
> >
> > from("direct:rollback")
> >         .log("saga transaction failed. deleting order
> ${headers.orderId}")
> >         .setHeader(Exchange.HTTP_URI,
> > simple("http://localhost:8000/orders/${headers.orderId}";))
> >         .setHeader(Exchange.HTTP_METHOD, constant("DELETE"))
> >         .to("http:dummyhost")
> >         .log("compensation call response ${body}")
> >         .end();
> >
> >
> >
> > Logs
> >
> > ====
> >
> > 2020-09-08 15:35:55.832  INFO 80448 --- [nio-8000-exec-2]
> > o.s.web.servlet.DispatcherServlet        : Completed initialization in
> > 11 ms
> > 2020-09-08 15:35:57.054  INFO 80448 --- [ qtp18025156-26] route1
> >                             : api response
> >
> >
> {"message":"success","businessObject":{"order_id":"43657a09-5c32-4303-9b14-73ab03e4e086","item_code":"XAH504004","item_qty":10}}
> > 2020-09-08 15:35:57.065 ERROR 80448 --- [ qtp18025156-26]
> > o.a.camel.processor.DefaultErrorHandler  : Failed delivery for
> > (MessageId: ID-5CG7324CR4-1599593718571-0-4 on ExchangeId:
> > ID-5CG7324CR4-1599593718571-0-1). Exhausted after delivery attempt: 1
> > caught: java.lang.Exception: This is a simulated error
> >
> > Message History
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------------------
> > RouteId              ProcessorId          Processor
> >                                                     Elapsed (ms)
> > [route1            ] [route1            ]
> > [jetty:http://0.0.0.0:8081/testtxn?httpMethodRestrict=GET
> >         ] [      1373]
> > [route1            ] [log1              ] [log
> >                                                   ] [         3]
> > [route1            ] [output1           ]
> > [saga[compensation:direct:rollback,propagation:REQUIRES_NEW]
> >         ] [         0]
> > [route1            ] [log2              ] [log
> >                                                   ] [         0]
> > [route1            ] [setBody1          ] [setBody[constant{{
> > "item_code" : "XAH504004", "item_qty" : 10 }}]             ] [
> > 0]
> > [route1            ] [setHeader1        ] [setHeader[Content-Type]
> >                                                   ] [         0]
> > [route1            ] [setHeader2        ] [setHeader[CamelHttpMethod]
> >                                                   ] [         0]
> > [route1            ] [setHeader3        ] [setHeader[CamelHttpUri]
> >                                                   ] [         0]
> > [route1            ] [to1               ] [http:dummyhost
> >                                                   ] [      1354]
> > [route1            ] [log3              ] [log
> >                                                   ] [         0]
> > [route1            ] [setHeader4        ] [setHeader[orderId]
> >                                                   ] [         6]
> > [route1            ] [throwException1   ]
> > [throwException[java.lang.Exception]
> >         ] [         0]
> >
> > Stacktrace
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------------------
> >
> > java.lang.Exception: This is a simulated error
> >         at
> >
> com.reji.poc.cluster.camelclustering.routes.SimpleJdbcDBRoute.configure(SimpleJdbcDBRoute.java:32)
> > ~[classes/:na]
> >         at
> >
> org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:465)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:403)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:384)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.impl.DefaultCamelContext$3.call(DefaultCamelContext.java:1023)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.impl.DefaultCamelContext$3.call(DefaultCamelContext.java:1020)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3266)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:1020)
> > ~[camel-core-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:150)
> > ~[camel-spring-boot-2.25.1.jar:2.25.1]
> >         at
> >
> org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:57)
> > ~[camel-spring-boot-2.25.1.jar:2.25.1]
> >         at
> >
> org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
> > ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE]
> >         at
> >
> org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
> > ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE]
> >         at
> >
> com.reji.poc.cluster.camelclustering.CamelApplication.main(CamelApplication.java:13)
> > ~[classes/:na]
> >
> > 2020-09-08 15:35:57.084  INFO 80448 --- [hread #1 - saga] route2
> >                             : saga transaction failed. deleting order
> >
>

Reply via email to