...
The Camel CDI component provides auto-configuration for Apache Camel using CDI as dependency injection framework based on convention-over-configuration. It auto-detects Camel routes available in the application and provides beans for common Camel primitives like Endpoint
, ProducerTemplate
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
, ExchangeCompletedEvent
, ...) as CDI events and provides a CDI events endpoint that can be used to consume / produce CDI events from / to Camel routes.
...
Multiple Camel contexts support
Any number of CamelContext
beans can actually be declared in the application as documented above. In that case, the CDI qualifiers declared on these CamelContext
beans are used to bind the Camel routes and other Camel primitives to the corresponding Camel contexts. From example, if the following beans get declared:
Code Block | ||
---|---|---|
| ||
@ApplicationScoped @ContextName("foo") class FooCamelContext extends DefaultCamelContext { } @ApplicationScoped @ContextName("bar") class BarCamelContext extends DefaultCamelContext { } @ContextName("foo") class RouteAdddedToFooContext extends RoutesBuilder { @Override public void configure() { // ... } } @ContextName("bar") class RouteAdddedToBarContext extends RoutesBuilder { @Override public void configure() { // ... } } @ContextName("baz") class RouteAdddedToBazContext extends RoutesBuilder { @Override public void configure() { // ... } } @MyQualifier class RouteNotAddedToAnyContext extends RoutesBuilder { @Override public void configure() { // ... } } |
The RoutesBuilder
beans qualified with @ContextName
get added to the corresponding CamelContext
beans. If no such CamelContext
bean exists, it gets automatically added by Camel CDI, as for the RouteAdddedToBazContext
bean. This only happens for the @ContextName
qualifier provided by Camel CDI. Hence the RouteNotAddedToAnyContext
bean qualified with the user-defined @MyQualifier
qualifier does not get added to any Camel contexts. That may be useful for Camel routes that may be required to be added later during the application execution.
Configuration properties
To configure the sourcing of the configuration properties used by Camel to resolve properties placeholders, you can declare a PropertiesComponent
bean qualified with @Named("properties")
, e.g.:
...