Debugger has been edited by willem jiang (Aug 16, 2008).

Change summary:

CAMEL-779 support to configure the debugger's logger dynamically

(View changes)

Content:

Debugger

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

At the time of writing the debugger breakpoints are not yet implemented - its work in progress

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

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

or

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

// lets run the camel route in debug mode
main = new Main();
main.enableDebug();
main.setApplicationContextUri("org/apache/camel/spring/debug/applicationContext.xml");
main.start();

// now lets test we have a debugger available
debugger = main.getDebugger();

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

public void testSendingSomeMessages() throws Exception {
    template.sendBodyAndHeader("direct:start", "Hello London", "to", "James");
    template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus");
}

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // add debugger as an interceptor. The debugger is an enhanced tracer that also
            // logs the exchanges at runtime. It is also a framework where we programatically
            // can access the internal states of Camel etc.
            getContext().addInterceptStrategy(new Debugger());

            from("direct:start").
                    process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            // do nothing
                        }

                        @Override
                        public String toString() {
                            return "MyProcessor";
                        }
                    }).
                    to("mock:a").
                    to("mock:b");
        }
    };
}

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.

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

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

See Also

See Tracer

Reply via email to