You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Camel CDI

The Camel CDI component provides auto-configuration for Apache Camel using CDI as dependency injection framework based on the convention-over-configuration principle. It auto-detects Camel routes available in the application and provides beans for common Camel primitives like EndpointProducerTemplate or TypeConverter. It implements standard Camel bean integration so that Camel annotations like @Consume@Produce and @PropertyInject can be used seamlessly in CDI beans. Besides, it bridges Camel events (e.g. RouteAddedEvent, CamelContextStartedEvent or ExchangeCompletedEvent) as CDI events and provides a CDI events endpoint that can be used to consume / produce CDI events from / to Camel routes.

While the Camel CDI component is available as of Camel 2.10, it's been rewritten in Camel 2.17 to better fit into the CDI programming model. Hence some of the features like the Camel events to CDI events bridge and the CDI events endpoint only apply starting Camel 2.17.

Auto-configured Camel context

Camel CDI automatically deploys and configures a CamelContext bean. That CamelContext bean is automatically instantiated, configured and started (resp. stopped) when the CDI container initialises (resp. shuts down). It can be injected in the application, e.g.:

@Inject
CamelContext context;

That default CamelContext bean is qualified with the built-in @Default qualifier, is scoped @ApplicationScoped and is of type DefaultCamelContext.

Note that this bean can be customised programmatically and other Camel context beans can be deployed in the application as well.

Auto-detecting Camel routes

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

 

 

 

 

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

  • No labels