Versions Compared

Key

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

...

Auto-detecting Camel routes

Camel CDI collects automatically collects all the RoutesBuilder beans in the application when the CDI container initialises and automatically , instantiates and add them to the CamelContext bean instance when the CDI container initialises. For example, adding a Camel route is as simple as declaring a class, e.g.:

Code Block
languagejava
class MyRouteBean extends RoutesBuilder {
 
	@Override
    public void configure() {
        from("direct:inbound")
            .to("mock:outbound");
    }
}

Custom Camel context customisation

 

Multiple Camel contexts support

 

 

As of 2.10 we now have support Contexts and Dependency Injection - JSR299 and Dependency Injection for Java - JSR330 as a dependency injection framework. This offers new opportunities to develop and deploy Apache Camel projects in Java EE 6 containers but also in standalone Java SE or CDI container

 

See Also

Camel events to CDI events

Camel provides a set of management events that can be subscribed to for listening to Camel context, service, route and exchange events. Camel CDI seamlessly translates these Camel events into CDI events that can be observed using CDI observer methods, e.g.:

Code Block
languagejava
void onContextStarting(@Observes CamelContextStartingEvent event) {
    // Called before the default Camel context is about to start
}

When multiple Camel contexts exist in the CDI container, the Camel context bean qualifiers, like @ContextName, can be used to refine the observer method resolution to a particular Camel context as specified in observer resolution, e.g.:

Code Block
languagejava
void onRouteStarted(@Observes @ContextName("foo") RouteStartedEvent event) {
    // Called after the route 'event.getRoute()' for the Camel context 'foo' has started
}
 
void onContextStarted(@Observes @Manual CamelContextStartedEvent event) {
    // Called after the the Camel context qualified with '@Manual' has started
}

Similarly, the @Default qualifier can be used to observe Camel events for the default Camel context if multiples contexts exist, e.g.:

Code Block
languagejava
void onExchangeCompleted(@Observes @Default ExchangeCompletedEvent event) {
    // Called after the exchange 'event.getExchange()' processing has completed
}

In that example, if no qualifier is specified, the @Any qualifier is implicitly assumed, so that corresponding events for all the Camel contexts get received.

Note that the support for Camel events translation into CDI events is only activated if observer methods listening for Camel events are detected in the deployment, and that per Camel context.

Configuration properties

 

Supported containers

 

See Also