Versions Compared

Key

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

...

The context component allows you to create new Camel Components from a CamelContext with a number of routes inside which is then treat it treated as a black box and , allowing you to refer to the local endpoints within the black box component from other CamelContexts.

It is similar to the Routebox component in idea, though the Context component tries to be really simple for end users; just a simple convention over configuration approach to refer to local endpoints inside a black box (CamelContext)the CamelContext Component.

Maven users will need to add the following dependency to their pom.xml for this component:

...

In this example we'll create a black box context, then we'll use it from another CamelContext.

Defining the

...

context component

First you need to create a CamelContext, add some routes in it, start it and then register the CamelContext into the Registry (JNDI, Spring, Guice or OSGi etc).

...

Code Block
xml
xml
<camelContext id="accounts" xmlns="http://camel.apache.org/schema/spring">
  <route> 
    <from uri="direct:purchaseOrder"/>
    ...
    <to uri="direct:invoice"/>
  </route>
</camelContext>

Using the

...

context component

Then in another CamelContext we can then refer to this "accounts black box" by just sending to accounts:purchaseOrder and consuming from accounts:invoice.

...

Code Block
xml
xml
<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>

Naming endpoints

A context component instance can have many public input and output endpoints that can be accessed from outside it's CamelContext. When there are many it is recommended that you use logical names for them to hide the middleware as shown above.

However when there is only one input, output or error/dead letter endpoint in a component we recommend using the common posix shell names in, out and err