Versions Compared

Key

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

...

Code Block
languagejava
@ApplicationScoped
@ContextName("foo")
class FooCamelContext extends DefaultCamelContext {
}

@ApplicationScoped
@ContextName("bar")@BarContextQualifier
class BarCamelContext extends DefaultCamelContext {
}
 
@ContextName("foo")
class RouteAdddedToFooContextRouteAdddedToFooCamelContext extends RoutesBuilder {
 
	@Override
    public void configure() {
        // ...
    }
}
 
@ContextName("bar")@BarContextQualifier
class RouteAdddedToBarContextRouteAdddedToBarCamelContext extends RoutesBuilder {
 
	@Override
    public void configure() {
        // ...
    }
}
 
@ContextName("baz")
class RouteAdddedToBazContextRouteAdddedToBazCamelContext extends RoutesBuilder {
 
	@Override
    public void configure() {
        // ...
    }
}
 
@MyQualifier@MyOtherQualifier
class RouteNotAddedToAnyContextRouteNotAddedToAnyCamelContext 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 RouteAdddedToBazCamelContext bean. This Note this only happens for the @ContextName qualifier provided by Camel CDI. Hence the RouteNotAddedToAnyContext RouteNotAddedToAnyCamelContext bean qualified with the user-defined @MyQualifier@MyOtherQualifier qualifier does not get added to any Camel contexts. That may be useful, for example, for Camel routes that may be required to be added later during the application execution.

The CDI qualifiers declared on the CamelContext beans are also used to bind the corresponding Camel primitives, e.g.:

Code Block
languagejava
@Inject
@ContextName("foo")
@Uri("direct:inbound")
ProducerTemplate producerTemplate;

@Inject
@BarContextQualifier
MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound

@Inject
@ContextName("baz")
@Uri("direct:inbound")
Endpoint endpoint;

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.:

...