Apache camel how to log route

When an Exception occurs in a route and is not caught by the exception manager, the route data is displayed, helping a lot to know what could have gone wrong.

When an exception is caught and managed, how can you have the same log?

I would have preferred to have something "callable" from the java part, for example in the processor, but something dsl style could be done as well.

Route logs usually look like this:

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                                  Elapsed (ms)
[route1            ] [cxf_process       ] [cxfrs://bean:myServer?bindingStyle=SimpleConsumer                             ] [     60029]
[route1            ] [to55              ] [direct:validateAndRedirect                                                    ] [     60029]
[route27           ] [setProperty37     ] [setProperty[operationName]                                                    ] [         0]
[route27           ] [setProperty38     ] [setProperty[Country]                                                          ] [         0]
[route27           ] [setProperty39     ] [setProperty[Language]                                                         ] [         0]
[route27           ] [process25         ] [my.package.ExtractUserMailProcessor@535f9aac                                  ] [         0]
[route27           ] [enrich25          ] [enrich[direct:checkAccess]                                                    ] [         0]
[route27           ] [recipientList1    ] [recipientList[simple{Simple: direct:${property.operationName}}]               ] [     60029]
[route28           ] [setHeader84       ] [setHeader[CamelCxfRsUsingHttpAPI]                                             ] [         0]
[route28           ] [setHeader85       ] [setHeader[CamelHttpPath]                                                      ] [         0]
[route28           ] [setHeader86       ] [setHeader[CamelHttpMethod]                                                    ] [         1]
[route28           ] [setHeader87       ] [setHeader[Content-Type]                                                       ] [         0]
[route28           ] [enrich9           ] [enrich[direct:wsClient]                                                       ] [     60029]
[route7            ] [to7               ] [cxfrs:bean:myClient                                                           ] [     60027]

Exchange
---------------------------------------------------------------------------------------------------------------------------------------

      

...

thanks in advance,

Francois

+3


source to share


2 answers


This is a message history EIP template

This page details this and how you can access the story yourself. org.apache.camel.util.MessageHelper#dumpMessageHistoryStacktrace

is what Camel uses to output this table you see above.



But as Konstantin wrote, you access history from Java code like this

List<MessageHistory> list = exchange.getProperty(Exchange.MESSAGE_HISTORY, List.class);

      

+3


source


After digging through the code, I found org.apache.camel.util.MessageHelper # dumpMessageHistoryStacktrace, which should do what I want.



0


source







All Articles