...
The event is based on the EventNotifer EventNotifier
emitting events such as ExchangeCreatedEvent
, ExchangeFailureEvent
etc. This allows you to have breakpoints when a given Exchange has failed. Or when they are done, so you can inspect the result etc.
...
Which then will only invoke the breakpoint callback for the "Hello Camel"
message.
Single step
In the Java editor the debugger is capable of single stepping when a breakpoint is hit. The idea in Camel is that you want to single step an Exchange so you can step through how its routed and follow it from the 3rd party tooling.
The Debugger
has API for single stepping. For example to single step the first message arrived in Camel you can do
Code Block |
---|
context.getDebugger().addSingleStepBreakpoint(breakpoint);
|
However what if you have multiple routes or the likes and only want to single step from route X, well you can just add a Condition
:
This beerCondition
will only match Exchange coming from the beer
route:
Code Block |
---|
beerCondition = new ConditionSupport() {
public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition definition) {
return "beer".equals(exchange.getFromRouteId());
}
};
|
So you just provide the condition when adding the breakpoint:
Code Block |
---|
// we only want to single step the beer route
context.getDebugger().addSingleStepBreakpoint(breakpoint, beerCondition);
|
And the routes could be as follows:
Code Block |
---|
public void configure() throws Exception {
// use debugger
context.setDebugger(new DefaultDebugger());
from("direct:start").routeId("foo").to("log:foo").to("log:bar").to("mock:result");
from("direct:beer").routeId("beer").to("log:beer").to("mock:result");
}
|
Which will cause the debugger to only single step
...
when a message arrives on beer
route:
Code Block |
---|
public void testDebug() throws Exception {
// we only want to single step the beer route
context.getDebugger().addSingleStepBreakpoint(breakpoint, beerCondition);
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Carlsberg");
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:beer", "Carlsberg");
assertMockEndpointsSatisfied();
assertEquals(2, logs.size());
assertEquals("Single stepping at log:beer with body: Carlsberg", logs.get(0));
assertEquals("Single stepping at mock:result with body: Carlsberg", logs.get(1));
}
|
Notes
- The single step feature should only allow one active at any time. So if there is already a single step message in process other messages should be disregarded from debugging
- Should other breakpoints be active during single step? In case you have another breakpoint somewhere which may get triggered?
- Should we add a fluent builder syntax for sugar, so its easier to use common conditions?