Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache camel how to log the route progress

When an Exception occurs in a route and isn't caught by an exception manager, the details of a route is displayed, helping a lot to know what could have gone wrong.

When the exception is caught and managed, how can it be possible to have the same kind of logs ?

I would prefer have something "callable" from the java part, for example in a Processor, but something in a dsl style could also do.

The route logging usually looks like :

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
---------------------------------------------------------------------------------------------------------------------------------------

...

Thx in advance,

François

like image 535
Francois Laroche Avatar asked Mar 19 '23 09:03

Francois Laroche


2 Answers

This is the message history EIP pattern

  • http://camel.apache.org/message-history.html

That page details about this, and how you can access the history yourself. The org.apache.camel.util.MessageHelper#dumpMessageHistoryStacktrace is what Camel uses itself to output that table you see above.

But as Konstantin wrote above, you get access to the history from Java code as follows

List<MessageHistory> list = exchange.getProperty(Exchange.MESSAGE_HISTORY, List.class);
like image 92
Claus Ibsen Avatar answered Mar 24 '23 20:03

Claus Ibsen


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

like image 35
Francois Laroche Avatar answered Mar 24 '23 19:03

Francois Laroche