{"id":15986883,"url":"https://github.com/astefanutti/camel-cdi","last_synced_at":"2025-03-17T15:32:26.492Z","repository":{"id":20061980,"uuid":"23330642","full_name":"astefanutti/camel-cdi","owner":"astefanutti","description":":camel: CDI extension for Apache Camel","archived":false,"fork":false,"pushed_at":"2017-11-13T16:05:09.000Z","size":1449,"stargazers_count":25,"open_issues_count":2,"forks_count":6,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-02-28T01:18:33.231Z","etag":null,"topics":["camel","cdi","java","javaee"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astefanutti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-25T22:17:27.000Z","updated_at":"2023-07-08T07:26:17.000Z","dependencies_parsed_at":"2022-08-31T03:54:01.590Z","dependency_job_id":null,"html_url":"https://github.com/astefanutti/camel-cdi","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astefanutti%2Fcamel-cdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astefanutti%2Fcamel-cdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astefanutti%2Fcamel-cdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astefanutti%2Fcamel-cdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astefanutti","download_url":"https://codeload.github.com/astefanutti/camel-cdi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243869480,"owners_count":20361022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camel","cdi","java","javaee"],"created_at":"2024-10-08T03:05:33.045Z","updated_at":"2025-03-17T15:32:26.114Z","avatar_url":"https://github.com/astefanutti.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CDI Extension for Camel\n\n[![Build Status][Travis badge]][Travis build] [![Coverage Status][Coveralls badge]][Coveralls build] [![Maven Central][Maven Central badge]][Maven Central build]\n\n[Travis badge]: https://travis-ci.org/astefanutti/camel-cdi.svg?branch=master\n[Travis build]: https://travis-ci.org/astefanutti/camel-cdi\n[Coveralls badge]: https://coveralls.io/repos/astefanutti/camel-cdi/badge.svg\n[Coveralls build]: https://coveralls.io/github/astefanutti/camel-cdi\n[Maven Central badge]: http://img.shields.io/maven-central/v/io.astefanutti.camel.cdi/camel-cdi.svg\n[Maven Central build]: http://repo1.maven.org/maven2/io/astefanutti/camel/cdi/camel-cdi/1.2.0/\n\n[CDI][] portable extension for Apache [Camel][] compliant with [JSR 346: Contexts and Dependency Injection for Java\u003csup\u003eTM\u003c/sup\u003e EE 1.2][JSR 346 1.2].\n\n[CDI]: http://www.cdi-spec.org/\n[Camel]: http://camel.apache.org/\n[JSR 299]: https://jcp.org/en/jsr/detail?id=299\n[JSR 346]: https://jcp.org/en/jsr/detail?id=346\n[JSR 346 1.1]: https://jcp.org/aboutJava/communityprocess/final/jsr346/index.html\n[JSR 346 1.2]: https://jcp.org/aboutJava/communityprocess/mrel/jsr346/index.html\n[CDI 1.1]: http://docs.jboss.org/cdi/spec/1.1/cdi-spec.html\n[CDI 1.2]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html\n\n## About\n\nVersion `1.2.0` of this component [has been merged](https://github.com/apache/camel/commit/0421c24dfcf992f3296ed746469771e3800200e3) into Apache Camel as part of [CAMEL-9201](https://issues.apache.org/jira/browse/CAMEL-9201). It now serves as an upstream project to explore possible evolution of the Camel CDI integration using the latest versions of the underlying technologies.\n\nHereafter is the original project statement:\n\u003e Since version `2.10` of Camel, the [Camel CDI][] component supports the integration of Camel in CDI enabled environments. However, some experiments and _battlefield_ tests prove it troublesome to use because of the following concerns:\n\u003e + It relies on older [CDI 1.0][JSR 299] version of the specification and makes incorrect usages of [container lifecycle events][] w.r.t. [Assignability of type variables, raw and parameterized types]. As a consequence, it does not work properly with newer implementation versions like Weld 2.x and containers like WildFly 8.x as reported in [CAMEL-7760][] among other issues.\n\u003e + It relies on Apache [DeltaSpike][] and its `BeanManagerProvider` class to retrieve the `BeanManager` instance during the CDI container initialisation. That may not be suitable in complex container configurations, for example, in multiple CDI containers per JVM context, as reported in [CAMEL-6338][] and that causes [CAMEL-6095][] and [CAMEL-6937][].\n\u003e + It relies on DeltaSpike and its [configuration mechanism][DeltaSpike Configuration Mechanism] to source configuration locations for the [Properties component][]. While this is suitable for most use cases, it relies on the `ServiceLoader` mechanism to support custom [configuration sources][ConfigSource] that may not be suitable in more complex container configurations and relates to [CAMEL-5986][].\n\u003e + Besides, while DeltaSpike is a valuable addition to the CDI ecosystem, Camel CDI having a direct dependency on it is questionable from a design standpoint as opposed to relying on standard Camel mechanism for producing the Camel Properties component and delegating, as a plugable strategy, the configuration sourcing concern and implementation choice to the application itself or eventually using the [Java EE Configuration JSR][] when available.\n\u003e + It declares a `CamelContext` CDI bean that's automatically instantiated and started with a `@PostConstruct` lifecycle callback called before the CDI container is completely initialized. That prevents, among other side effects like [CAMEL-9336][], proper configuration of the Camel context as reported in [CAMEL-8325][] and advising of Camel routes as documented in [Camel AdviceWith][].\n\u003e + It uses the `@ContextName` annotation to bind routes to the `CamelContext` instance specified by name as an attempt to provide support for multiple Camel contexts per application. However, that is an incomplete feature from the CDI programming model standpoint as discussed in [CAMEL-5566][] and that causes [CAMEL-5742][].\n\n\u003e The objective of this project is to alleviate all these concerns, provide additional features, and have that improved version of the Camel CDI component contributed back into the official codeline.\n\n[Camel CDI]: http://camel.apache.org/cdi.html\n[DeltaSpike]: https://deltaspike.apache.org/\n[DeltaSpike Configuration Mechanism]: https://deltaspike.apache.org/configuration.html\n[ConfigSource]: https://deltaspike.apache.org/configuration.html#custom-config-sources\n[Camel AdviceWith]: http://camel.apache.org/advicewith.html\n[Properties component]: http://camel.apache.org/properties\n[CAMEL-5566]: https://issues.apache.org/jira/browse/CAMEL-5566\n[CAMEL-5742]: https://issues.apache.org/jira/browse/CAMEL-5742\n[CAMEL-5986]: https://issues.apache.org/jira/browse/CAMEL-5986\n[CAMEL-6095]: https://issues.apache.org/jira/browse/CAMEL-6095\n[CAMEL-6336]: https://issues.apache.org/jira/browse/CAMEL-6336\n[CAMEL-6338]: https://issues.apache.org/jira/browse/CAMEL-6338\n[CAMEL-6937]: https://issues.apache.org/jira/browse/CAMEL-6937\n[CAMEL-7760]: https://issues.apache.org/jira/browse/CAMEL-7760\n[CAMEL-8325]: https://issues.apache.org/jira/browse/CAMEL-8325\n[CAMEL-9336]: https://issues.apache.org/jira/browse/CAMEL-9336\n[container lifecycle events]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#init_events\n[Assignability of type variables, raw and parameterized types]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#observers_assignability\n[Java EE Configuration JSR]: http://javaeeconfig.blogspot.ch/\n\n## Getting Started\n\n#### Using Maven\n\nAdd the `camel-cdi` library as a dependency:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.astefanutti.camel.cdi\u003c/groupId\u003e\n    \u003cartifactId\u003ecamel-cdi\u003c/artifactId\u003e\n    \u003cversion\u003e1.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Required Dependencies\n\nBesides depending on Camel (`camel-core` and `camel-core-osgi` optionally), Camel CDI requires a CDI enabled environment running in Java 8 or greater.\n\n#### Supported Containers\n\nThis version of Camel CDI is currently successfully tested with the following containers:\n\n| Container             | Version        | Environment                        |\n| --------------------- | -------------- | ---------------------------------- |\n| [Weld][]              | `2.4.0.Final`  | Java SE 8 / [CDI 1.2][JSR 346 1.2] |\n| [OpenWebBeans][]      | `1.7.0`        | Java SE 8 / [CDI 1.2][JSR 346 1.2] |\n| [WildFly 8][WildFly]  | `8.2.1.Final`  | [Java EE 7][]                      |\n| [WildFly 9][WildFly]  | `9.0.2.Final`  | [Java EE 7][]                      |\n| [WildFly 10][WildFly] | `10.1.0.Final` | [Java EE 7][]                      |\n| [WildFly Camel][]     | `4.3.0`        | [Java EE 7][]                      |\n| [Karaf][]\u003cbr/\u003e[PAX CDI Weld][] | `4.0.4`\u003cbr/\u003e`1.0.0.RC1` | [OSGi 6][] |\n\nWildFly 8.1 requires to be patched with Weld 2.2+ as documented in [Weld 2.2 on WildFly][].\n\n[Karaf]: https://karaf.apache.org\n[OpenWebBeans]: http://openwebbeans.apache.org/\n[PAX CDI Weld]: https://ops4j1.jira.com/wiki/display/PAXCDI/Pax+CDI\n[Weld]: http://weld.cdi-spec.org/\n[WildFly]: http://www.wildfly.org/\n[WildFly Camel]: https://github.com/wildfly-extras/wildfly-camel\n\n[Java EE 7]: https://jcp.org/en/jsr/detail?id=342\n[OSGi 6]: https://www.osgi.org/osgi-release-6-javadoc/\n\n[Weld 2.2 on WildFly]: http://weld.cdi-spec.org/news/2014/04/15/weld-220-final/\n\n## Usage\n\n#### CDI Event Camel Endpoint\n\nThe CDI event endpoint bridges the [CDI events][] facility with the Camel routes so that CDI events can be seamlessly observed / consumed (respectively produced / fired) from Camel consumers (respectively by Camel producers).\n\nThe `CdiEventEndpoint\u003cT\u003e` bean can be used to observe / consume CDI events whose _event type_ is `T`, for example:\n\n```java\n@Inject\nCdiEventEndpoint\u003cString\u003e cdiEventEndpoint;\n\nfrom(cdiEventEndpoint).log(\"CDI event received: ${body}\");\n```\n\nThis is equivalent to writing:\n\n```java\n@Inject\n@Uri(\"direct:event\")\nProducerTemplate producer;\n\nvoid observeCdiEvents(@Observes String event) {\n    producer.sendBody(event);\n}\n\nfrom(\"direct:event\").log(\"CDI event received: ${body}\");\n```\n\nConversely, the `CdiEventEndpoint\u003cT\u003e` bean can be used to produce / fire CDI events whose _event type_ is `T`, for example:\n\n```java\n@Inject\nCdiEventEndpoint\u003cString\u003e cdiEventEndpoint;\n\nfrom(\"direct:event\").to(cdiEventEndpoint).log(\"CDI event sent: ${body}\");\n```\n\nThis is equivalent to writing:\n\n```java\n@Inject\nEvent\u003cString\u003e event;\n\nfrom(\"direct:event\").process(new Processor() {\n    @Override\n    public void process(Exchange exchange) {\n        event.fire(exchange.getBody(String.class));\n    }\n}).log(\"CDI event sent: ${body}\");\n```\n\nOr using a Java 8 lambda expression:\n```java\n@Inject\nEvent\u003cString\u003e event;\n\nfrom(\"direct:event\")\n    .process(exchange -\u003e event.fire(exchange.getIn().getBody(String.class)))\n    .log(\"CDI event sent: ${body}\");\n```\n\nThe type variable `T`, respectively the qualifiers, of a particular `CdiEventEndpoint\u003cT\u003e` injection point are automatically translated into the parameterized _event type_, respectively into the _event qualifiers_, e.g.:\n\n```java\n@Inject\n@FooQualifier\nCdiEventEndpoint\u003cList\u003cString\u003e\u003e cdiEventEndpoint;\n\nfrom(\"direct:event\").to(cdiEventEndpoint);\n\nvoid observeCdiEvents(@Observes @FooQualifier List\u003cString\u003e event) {\n    logger.info(\"CDI event: {}\", event);\n}\n```\n\nWhen multiple Camel contexts exist in the CDI container, the `@ContextName` qualifier can be used to qualify the `CdiEventEndpoint\u003cT\u003e` injection points, e.g.:\n\n```java\n@Inject\n@ContextName(\"foo\")\nCdiEventEndpoint\u003cList\u003cString\u003e\u003e cdiEventEndpoint;\n// Only observes / consumes events having the @ContextName(\"foo\") qualifier\nfrom(cdiEventEndpoint).log(\"Camel context 'foo' \u003e CDI event received: ${body}\");\n// Produces / fires events with the @ContextName(\"foo\") qualifier\nfrom(\"...\").to(cdiEventEndpoint);\n\nvoid observeCdiEvents(@Observes @ContextName(\"foo\") List\u003cString\u003e event) {\n    logger.info(\"Camel context 'foo' \u003e CDI event: {}\", event);\n}\n```\n\nNote that the CDI event Camel endpoint dynamically adds an [observer method][] for each unique combination of _event type_ and _event qualifiers_ and solely relies on the container typesafe [observer resolution][], which leads to an implementation as efficient as possible.\n\nBesides, as the impedance between the _typesafe_ nature of CDI and the _dynamic_ nature of the [Camel component][] model is quite high, it is not possible to create an instance of the CDI event Camel endpoint via [URIs][]. Indeed, the URI format for the CDI event component is:\n\n```\ncdi-event://PayloadType\u003cT1,...,Tn\u003e[?qualifiers=QualifierType1[,...[,QualifierTypeN]...]]\n```\n\nWith the authority `PayloadType` (respectively the `QualifierType`) being the URI escaped fully qualified name of the payload (respectively qualifier) raw type followed by the type parameters section delimited by angle brackets for payload parameterized type. Which leads to _unfriendly_ URIs, e.g.:\n\n```\ncdi-event://org.apache.camel.cdi.se.pojo.EventPayload%3Cjava.lang.Integer%3E?qualifiers=org.apache.camel.cdi.se.qualifier.FooQualifier%2Corg.apache.camel.cdi.se.qualifier.BarQualifier\n```\n\nBut more fundamentally, that would prevent efficient binding between the endpoint instances and the observer methods as the CDI container doesn't have any ways of discovering the Camel context model during the deployment phase.\n\n[CDI events]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#events\n[observer method]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#observer_methods\n[observer resolution]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#observer_resolution\n[Camel component]: http://camel.apache.org/component.html\n[URIs]: http://camel.apache.org/uris.html\n\n#### Camel Events to CDI Events\n\nCamel provides a set of [management events][] that can be subscribed to for listening to Camel context, service, route and exchange events. This version of Camel CDI seamlessly translates these Camel events into CDI events that can be observed using CDI [observer methods][], e.g.:\n\n```java\nvoid onContextStarting(@Observes CamelContextStartingEvent event) {\n    // Called before the default Camel context is about to start\n}\n\n```\n\nWhen multiple Camel contexts exist in the CDI container, the `@ContextName` qualifier can be used to refine the observer method resolution to a particular Camel context as specified in [observer resolution][], e.g.:\n\n```java\nvoid onRouteStarted(@Observes @ContextName(\"first\") RouteStartedEvent event) {\n    // Called after the route (event.getRoute()) for the\n    // Camel context (\"first\") has started\n}\n\n```\n\nSimilarly, the `@Default` qualifier can be used to observe Camel events for the _default_ Camel context if multiples contexts exist, e.g.:\n\n```java\nvoid onExchangeCompleted(@Observes @Default ExchangeCompletedEvent event) {\n    // Called after the exchange (event.getExchange()) processing has completed\n}\n\n```\n\nIn that example, if no qualifier is specified, the `@Any` qualifier is implicitly assumed, so that corresponding events for all the Camel contexts deployed get received.\n\nNote 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.\n\n[management events]: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/event/package-summary.html\n[observer methods]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#observer_methods\n\n#### Type Converter Beans\n\nCDI beans annotated with the `@Converter` annotation are automatically registered into all the deployed Camel contexts, e.g.:\n\n```java\n@Converter\npublic class TypeConverter {\n\n    @Converter\n    public Output convert(Input input) {\n        //...\n    }\n}\n```\nNote that CDI injection is supported within the type converters.\n\n#### Multiple Camel Contexts\n\nThe `@ContextName` qualifier can be used to declared multiple Camel contexts, e.g.:\n\n```java\n@ApplicationScoped\n@ContextName(\"foo\")\nclass FooCamelContext extends DefaultCamelContext {\n\n}\n\n@ApplicationScoped\n@ContextName(\"bar\")\nclass BarCamelContext extends DefaultCamelContext {\n\n}\n```\n\nAnd then use that same qualifier to declare [injected fields][], e.g.:\n\n```java\n@Inject\n@ContextName(\"foo\")\nCamelContext fooCamelContext;\n\n@Inject\n@ContextName(\"bar\")\nCamelContext fooCamelContext;\n```\n\nNote that Camel CDI provides the `@ContextName` qualifier for convenience though any [CDI qualifiers][] can be used to declare the Camel context beans and the injection points.\n\n[CDI qualifiers]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#qualifiers\n[injected fields]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#injected_fields\n\n#### Configuration Properties\n\nCamel CDI relies on _standard_ Camel abstractions and CDI mechanisms. The configuration sourcing concern is delegated to the application so that it can provide any `PropertiesComponent` bean that's tailored for its need, e.g.:\n\n```java\n@Produces\n@ApplicationScoped\n@Named(\"properties\")\nPropertiesComponent propertiesComponent() {\n    Properties properties = new Properties();\n    properties.put(\"property\", \"value\");\n    PropertiesComponent component = new PropertiesComponent();\n    component.setInitialProperties(properties);\n    component.setLocation(\"classpath:placeholder.properties\");\n    return component;\n}\n\n```\n\n#### Camel Context Customization\n\nAny `CamelContext` class can be used to declare a custom Camel context bean that uses the `@PostConstruct` and `@PreDestroy` lifecycle callbacks, e.g.:\n\n```java\n@ApplicationScoped\nclass CustomCamelContext extends DefaultCamelContext {\n\n    @PostConstruct\n    void customize() {\n        // Sets the Camel context name\n        setName(\"custom\");\n        // Adds properties location\n        getComponent(\"properties\", PropertiesComponent.class)\n            .setLocation(\"classpath:placeholder.properties\");\n    }\n\n    @PreDestroy\n    void cleanUp() {\n        // ...\n    }\n}\n```\n\n[Producer][producer method] and [disposer][disposer method] methods can be used as well to customize the Camel context bean, e.g.:\n\n```java\nclass CamelContextFactory {\n\n    @Produces\n    @ApplicationScoped\n    CamelContext customize() {\n        DefaultCamelContext context = new DefaultCamelContext();\n        context.setName(\"custom\");\n        return context;\n    }\n\n    void cleanUp(@Disposes CamelContext context) {\n        // ...\n    }\n}\n```\n\nSimilarly, [producer fields][producer field] can be used, e.g.:\n\n```java\n@Produces\n@ApplicationScoped\nCamelContext context = new CustomCamelContext();\n\nclass CustomCamelContext extends DefaultCamelContext {\n\n    CustomCamelContext() {\n        setName(\"custom\");\n    }\n}\n```\n\nThis pattern can be used to avoid having the Camel context started automatically at deployment time by calling the `setAutoStartup` method, e.g.:\n\n```java\n@ApplicationScoped\nclass ManualStartupCamelContext extends DefaultCamelContext {\n\n    @PostConstruct\n    void manual() {\n        setAutoStartup(false);\n    }\n}\n\n```\n\n[producer method]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#producer_method\n[disposer method]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#disposer_method\n[producer field]: http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#producer_field\n\n#### Camel Route Builders\n\nCamel CDI detects any beans of type `RouteBuilder` and automatically adds the declared routes to the corresponding Camel context at deployment time, e.g.:\n\n```java\n@ContextName(\"foo\")\nclass FooCamelContextRoute extends RouteBuilder {\n\n    @Override\n    public void configure() {\n        from(\"direct:inbound\")\n            .setHeader(\"context\").constant(\"foo\")\n            .to(\"mock:outbound\");\n    }\n}\n```\n\n#### Camel CDI Beans\n\nCamel CDI declares some producer method beans that can be used to inject Camel objects of types `Endpoint`, `MockEndpoint`, `ProducerTemplate` and `TypeConverter`, e.g.:\n\n```java\n@Inject\n@Uri(\"direct:inbound\")\nProducerTemplate producerTemplate;\n\n@Inject\nMockEndpoint outbound; // URI defaults to the member name, i.e. mock:outbound\n\n@Inject\n@Uri(\"direct:inbound\")\nEndpoint endpoint;\n\n@Inject\n@ContextName(\"foo\")\nTypeConverter converter;\n```\n\n#### Camel Annotations Support\n\nCamel comes with a set of [annotations][Camel annotations] that are supported by Camel CDI for both standard CDI injection and Camel [bean integration][], e.g.:\n\n```java\n@PropertyInject(\"property\")\nString property;\n\n@Produce(uri = \"mock:outbound\")\nProducerTemplate producer;\n\n// Equivalent to:\n// @Inject @Uri(\"direct:inbound\")\n// Endpoint endpoint;\n@EndpointInject(uri = \"direct:inbound\")\nEndpoint endpoint;\n\n// Equivalent to:\n// @Inject @ContextName(\"foo\") @Uri(\"direct:inbound\")\n// Endpoint contextEndpoint;\n@EndpointInject(uri = \"direct:inbound\", context = \"foo\")\nEndpoint contextEndpoint;\n\n// Equivalent to:\n// @Inject MyBean bean;\n@BeanInject\nMyBean bean;\n\n@Consume(uri = \"seda:inbound\")\nvoid consume(@Body String body) {\n    //...\n}\n```\n\n[Camel annotations]: http://camel.apache.org/bean-integration.html#BeanIntegration-Annotations\n[bean integration]: http://camel.apache.org/bean-integration.html\n\n#### Black Box Camel Contexts\n\nThe [context component][] enables the creation of Camel components out of Camel contexts and the mapping of local endpoints within these components from other Camel contexts based on the identifiers used to register these  _black box_ Camel contexts in the Camel registry.\n\nFor example, given the two Camel contexts declared as CDI beans:\n\n```java\n@ApplicationScoped\n@Named(\"blackbox\")\n@ContextName(\"foo\")\nclass FooCamelContext extends DefaultCamelContext {\n\n}\n```\n\n```java\n@ApplicationScoped\n@ContextName(\"bar\")\nclass BarCamelContext extends DefaultCamelContext {\n\n}\n```\n\nWith the `foo` Camel context being registered into the Camel registry as `blackbox` by annotating it with the `@Named(\"blackbox\")` qualifier, and the following route being added to it:\n\n```java\n@ContextName(\"foo\")\nFooRouteBuilder extends RouteBuilder {\n\n    @Override\n    public void configure() {\n        from(\"direct:in\")/*...*/.to(\"direct:out\");\n    }\n}\n```\n\nIt is possible to refer to the local endpoints of `foo` from the `bar` Camel context route:\n\n```java\n@ContextName(\"bar\")\nBarRouteBuilder extends RouteBuilder {\n\n    @Override\n    public void configure() {\n        from(\"...\").to(\"blackbox:in\");\n        //...\n        from(\"blackbox:out\").to(\"...\");\n    }\n}\n```\n\n[context component]: http://camel.apache.org/context.html\n\n## License\n\nCopyright © 2014-2016, Antonin Stefanutti\n\nPublished under Apache Software License 2.0, see LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastefanutti%2Fcamel-cdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastefanutti%2Fcamel-cdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastefanutti%2Fcamel-cdi/lists"}