...
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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
- CDI Web site
- Simple Camel CDI BootStrap project
- JSR299 and JSR330 reference documentations
- Apache DeltaSpike project - CDI extensions and JavaSE BootStrap
- CDI revealed by Antonio Goncalves - part 1, part 2, part 3 and OpenEJB team - see examples
- Apache implementation of the specs JSR299, 330 - OpenWebbeans and Apache OpenEJB which provide the container to deploy CDI projects
- Apache Karaf featured with OpenEJB and CDI - Apache KarafEE