Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
{snippet:id=e2|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceFormatterTest.java}

Using Destination for custom processing and routing

Avaiable as of Camel 2.0

Tracer now supports custom processing of trace events. This can be used to route a trace event to a JPA endpoint for persistence in a database.

This works by Camel creates a new TraceEventExchange containing:

  • snapshot of the original traced Exchange as a immutable TraceEventMessage containing String values of the fields, when the interception occurred. This ensures the fields contains the exact data at the given time of interception.
  • the original Exchange can be accessed using getTracedExchange()
Warning

Beware to access the original Exchange to avoid causing any side effects or alter its state. Prefer to access the information from TraceEventMessage

Camel routes the TraceEventExchange synchronously from the point of interception. When its completed Camel will continue routing the original Exchange.

The sample below demonstrates this feature:

Wiki Markup
{snippet:id=e1|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInterceptorDestinationTest.java}

Then we can configure a route for the traced messages:

Code Block

   from("direct:traced").process(new MyTraceMessageProcessor()).to("file://myapp/logs/trace);

And our processor where we can process the TraceEventMessage. Here we want to create a CSV format of the trace event to be stored as a file. We do this by constructing the CSV String and the replace the IN body with our String instead of the TraceEventMessage.

Wiki Markup
{snippet:id=e2|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInterceptorDestinationTest.java}

See Also