Versions Compared

Key

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

Debugger

Available as of Camel 2.6

Camel Debugger is much related to Tracer, in fact they are sisters. Debugger is a enhanced tracer with a debugger framework so that tooling can be developed to easily monitor Camel routes, trace messages and set breakpoints at points in a route etc.

Warning
title@deprecated

The debugger is @deprecated and is removed in Camel 2.0.

The Tracer is sufficient in many cases, and if you want to do some debugging yourself then you can use Intercept.
Or try out Eclipse based tooling that supports visual and integrated debugger in Eclipse, being able to debug Camel routing - FUSE Integration Designer

The Debugger is an InterceptStrategy which can be applied to a DefaultCamelContext or SpringCamelContext to ensure that there is a DebugInterceptor created for every node in the DSL.

You can grab the debugger via the Debugger.getDebugger(context) method or via the Main.getDebugger() method - which returns null if it is not enabled.

You can enable or disable the debugger's logging dynamically, by calling the debugger's setEnable method.

Enabling from Main

To enable debugging from the main run

About the Debugger

The Debugger allows tooling or the likes to attach breakpoints which is being invoked when Exchanges is being routed.

Default implementation

...

Camel provides a default implementation

org.apache.camel.

...

impl.DefaultDebugger which you can set on the CamelContext using the setDebugger method.
Likewise you can get hold of the Debugger using the getDebugger method on CamelContext.

The

or

Code Block

java org.apache.camel.spring.Main -debug

and the debugger will be active.

Programmatically using the debugger

You can use the Spring org.apache.camel.spring.Main class directly to invoke your Camel routes using a spring XML file using debug as the following test case...

Wiki Markup
{snippet:id=example|lang=java|url=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/debug/DebugTest.java}

The Debugger can also be added to the routes as an interceptor as the following unit test below demonstrates:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/DebugInterceptorTest.java}

About the Debugger

The Debugger has access to every single DebugInterceptor for each node in the Camel EIP route. You can look up the individual interceptor by the Node ID where you can access

  • the Breakpoint object
  • the list of Exchanges sent to this node
  • the Predicate used to determine if messages are logged to the list

Accessing the Route Definitions

You can easily access all of the available route definitions from the Main instance via the getRouteDefinitions() method.

Code Block

List<RouteType> routes = main.getRouteDefinitions();

you can then navigate the route and see its inputs and outputs etc

See Also

spi.Debugger has methods to attach and remove breakpoints. And to suspend/resume all breakpoints etc.
You can also attach a condition to the breakpoint so it only reacts if the condition matches.

Easily debugging Camel routes from camel-test

If you are developing unit tests using the camel-test component, then the Debugger comes out of the box.

Example

In this unit test

Code Block

public class DebugTest extends CamelTestSupport

We want to debug the following route
TODO: e2

Which can easily done by overriding the debugBefore method as shown
TODO: e1

Then from your Java editor just add a breakpoint inside the debugBefore method. Then fire up the unit test and wait for the Java editor to hit the breakpoint. Then you can inspect the Exchange during debugging while it advances during routing. The ProcessorDefinition and the id and shortName parameters is all information which tells you where in the route the breakpoint was hit.

See Also