...
Available as of Camel 2.7
Warning |
---|
Deprecated do NOT use |
The context component allows you to create new Camel Components from a CamelContext with a number of routes which is then treated as a black box, allowing you to refer to the local endpoints within the component from other CamelContexts.
...
Maven users will need to add the following dependency to their pom.xml
for this component:
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-context</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
URI format
Code Block |
---|
context:camelContextId:localEndpointName[?options]
|
Or you can omit the "context:" prefix.
Code Block |
---|
camelContextId:localEndpointName[?options]
|
...
This can be done in the usual Camel way from this test case (see the createRegistry() method); this example shows Java and JNDI being used...
Code Block |
---|
// lets create our black box as a camel context and a set of routes
DefaultCamelContext blackBox = new DefaultCamelContext(registry);
blackBox.setName("blackBox");
blackBox.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// receive purchase orders, lets process it in some way then send an invoice
// to our invoice endpoint
from("direct:purchaseOrder").
setHeader("received").constant("true").
to("direct:invoice");
}
});
blackBox.start();
registry.bind("accounts", blackBox);
|
Notice in the above route we are using pure local endpoints (direct and seda). Also note we expose this CamelContext using the accounts ID. We can do the same thing in Spring via
Code Block | ||||
---|---|---|---|---|
| ||||
<camelContext id="accounts" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:purchaseOrder"/>
...
<to uri="direct:invoice"/>
</route>
</camelContext>
|
...
For example if we wish to then expose this accounts black box on some middleware (outside of the black box) we can do things like...
Code Block | ||||
---|---|---|---|---|
| ||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- consume from an ActiveMQ into the black box -->
<from uri="activemq:Accounts.PurchaseOrders"/>
<to uri="accounts:purchaseOrders"/>
</route>
<route>
<!-- lets send invoices from the black box to a different ActiveMQ Queue -->
<from uri="accounts:invoice"/>
<to uri="activemq:UK.Accounts.Invoices"/>
</route>
</camelContext>
|
...