上で説明したように、実際にはアプリケーションで任意の数の CamelContext
Bean を宣言できます。その場合、これらの CamelContext
Bean で宣言された CDI 修飾子は、対応する Camel コンテキストへの Camel ルートおよび他の Camel プリミティブを BIND するために使用されます。例から、次の Bean が宣言された場合:
@ApplicationScoped
@ContextName("foo")
class FooCamelContext extends DefaultCamelContext {
}
@ApplicationScoped
@BarContextQualifier
class BarCamelContext extends DefaultCamelContext {
}
@ContextName("foo")
class RouteAddedToFooCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@BarContextQualifier
class RouteAddedToBarCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@ContextName("baz")
class RouteAddedToBazCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@MyOtherQualifier
class RouteNotAddedToAnyCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@ApplicationScoped
@ContextName("foo")
class FooCamelContext extends DefaultCamelContext {
}
@ApplicationScoped
@BarContextQualifier
class BarCamelContext extends DefaultCamelContext {
}
@ContextName("foo")
class RouteAddedToFooCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@BarContextQualifier
class RouteAddedToBarCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@ContextName("baz")
class RouteAddedToBazCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
@MyOtherQualifier
class RouteNotAddedToAnyCamelContext extends RouteBuilder {
@Override
public void configure() {
// ...
}
}
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
@ContextName
で修飾された RoutesBuilder
Bean は、Camel CDI によって対応する CamelContext
Bean に自動的に追加されます。そのような CamelContext
Bean が存在しない場合は、RouteAddedToBazCamelContext
Bean の場合と同様に、自動的に作成されます。これは、Camel CDI によって提供される @ContextName
修飾子に対してのみ発生することに注意してください。したがって、ユーザー定義の @MyOtherQualifier
修飾子で修飾された RouteNotAddedToAnyCamelContext
Bean は、どの Camel コンテキストにも追加されません。これは、たとえば、後でアプリケーションの実行中に追加する必要がある Camel ルートの場合に役立ちます。
Camel バージョン 2.17.0 以降、Camel CDI はあらゆる種類の CamelContext
Bean (例: DefaultCamelContext
) を管理できます。以前のバージョンでは、タイプ CdiCamelContext
の Bean しか管理できないため、拡張する必要があります。
CamelContext
Bean で宣言された CDI 修飾子は、対応する Camel プリミティブを BIND するためにも使用されます。以下に例を示します。
@Inject
@ContextName("foo")
@Uri("direct:inbound")
ProducerTemplate producerTemplate;
@Inject
@ContextName("foo")
@Uri("direct:inbound")
FluentProducerTemplate fluentProducerTemplate;
@Inject
@BarContextQualifier
MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound
@Inject
@ContextName("baz")
@Uri("direct:inbound")
Endpoint endpoint;
@Inject
@ContextName("foo")
@Uri("direct:inbound")
ProducerTemplate producerTemplate;
@Inject
@ContextName("foo")
@Uri("direct:inbound")
FluentProducerTemplate fluentProducerTemplate;
@Inject
@BarContextQualifier
MockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound
@Inject
@ContextName("baz")
@Uri("direct:inbound")
Endpoint endpoint;
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow