camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Routebox
Date Thu, 10 Feb 2011 16:40:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Routebox">Routebox</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~jstrachan">James
Strachan</a>
    </h4>
        <br/>
                         <h4>Changes (45)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-changed-lines" >h2. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">Routebox</span>
<span class="diff-added-words"style="background-color: #dfd;">Context</span> Component
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >*Available as of Camel <span
class="diff-changed-words">2.<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">6</span><span
class="diff-added-chars"style="background-color: #dfd;">7</span>*</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
*routebox* component enables the creation of specialized endpoints that offer encapsulation
and a strategy based indirection service to a collection of camel routes hosted in an automatically
created or user injected camel context. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
*context* component allows you to create a CamelContext with a number of routes inside then
treat it as a black box and refer to the local endpoints within the black box from other CamelContexts.
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Routebox
endpoints are camel endpoints that may be invoked directly on camel routes. The routebox endpoint
performs the following key functions <br>    * encapsulation - acts as a blackbox, hosting
a collection of camel routes stored in an inner camel context. The inner context is fully
under the control of the routebox component and is *JVM bound*.  <br>    * strategy
based indirection - direct payloads sent to the routebox endpoint along a camel route to specific
inner routes based on a user defined internal routing strategy or a dispatch map. <br>
   * exchange propagation - forward exchanges modified by the routebox endpoint to the next
segment of the camel route.  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">It
is similar to the [Routebox] component, 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). <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
routebox component supports both consumer and producer endpoints.  <br> <br>Producer
endpoints are of two flavors <br>    * Producers that send or dispatch incoming requests
to a external routebox consumer endpoint  <br>    * Producers that directly invoke routes
in an internal embedded camel context thereby not sending requests to an external consumer.
  <br> <br></td></tr>
            <tr><td class="diff-unchanged" >Maven users will need to add the following
dependency to their {{pom.xml}} for this component: <br>{code:xml} <br>&lt;dependency&gt;
<br>    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;artifactId&gt;camel-routebox&lt;/artifactId&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;artifactId&gt;camel-context&lt;/artifactId&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;version&gt;x.x.x&lt;/version&gt;
<br>    &lt;!-- use the same version as your Camel core version --&gt; <br>&lt;/dependency&gt;
<br>{code} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
<br>h3. The need for a Camel Routebox endpoint <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
routebox component is designed to ease integration in complex environments needing <br>
 * a large collection of routes and <br>  * involving a wide set of endpoint technologies
needing integration in different ways    <br> <br>In such environments, it is
often necessary to craft an integration solution by creating a sense of layering among camel
routes effectively organizing them into  <br>  * Coarse grained or higher level routes
- aggregated collection of inner or lower level routes exposed as Routebox endpoints that
represent an integration focus area. For example <br>      ||Focus Area||Coarse grained
Route Examples||  <br>      |Department Focus|HR routes, Sales routes etc| <br>
     |Supply chain &amp; B2B Focus|Shipping routes, Fulfillment routes, 3rd party services
etc| <br>      |Technology Focus|Database routes, JMS routes, Scheduled batch routes
etc| <br>  * Fine grained routes - routes that execute a singular and specific business
and/or integration pattern. <br> <br>Requests sent to Routebox endpoints on coarse
grained routes can then delegate requests to inner fine grained routes to achieve a specific
integration objective, collect the final inner result, and continue to progress to the next
step along the coarse-grained route. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. URI format <br> <br>{code}
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">routebox:routeboxname[?options]</span>
<span class="diff-added-words"style="background-color: #dfd;">context:camelContextId:localEndpointName[?options]</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">You
can append query options to the URI in the following format, {{?option=value&amp;option=value&amp;...}}
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Or
you can omit the &quot;context:&quot; prefix. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3.
Options <br>{warning:title=Routebox options subject to change} <br>The Routebox
component will be revisited in upcoming releases to see if it can be further simplified, be
more intuitive and user friendly. Watch this space!!!  <br>{warning} <br> <br>{div:class=confluenceTableSmall}
<br>|| Name || Default Value || Description || <br>| {{dispatchStrategy}} | {{null}}
| A string representing a key in the Camel Registry matching an object value implementing
the interface _org.apache.camel.component.routebox.strategy.RouteboxDispatchStrategy_ | <br>|
{{dispatchMap}} | {{null}} | A string representing a key in the Camel Registry matching an
object value of the type HashMap&lt;String, String&gt;. The HashMap key should contain
strings that can be matched against the value set for the exchange header *ROUTE_DISPATCH_KEY*.
The HashMap value should contain inner route consumer URI&#39;s to which requests should
be directed. | <br>| {{innerContext}} | {{auto created}} | A string representing a key
in the Camel Registry matching an object value of the type _org.apache.camel.CamelContext_.
If a CamelContext is not provided by the user a CamelContext is automatically created for
deployment of inner routes. | <br>| {{innerRegistry}} | {{null}} | A string representing
a key in the Camel Registry matching an object value that implements the interface _org.apache.camel.spi.Registry_.
If Registry values are utilized by inner routes to create endpoints, an innerRegistry parameter
must be provided | <br>| {{routeBuilders}} | {{empty List}} | A string representing
a key in the Camel Registry matching an object value of the type _List&lt;org.apache.camel.builder.RouteBuilder&gt;_.
If the user does not supply an innerContext pre-primed with inner routes, the routeBuilders
option must be provided as a non-empty list of RouteBuilders containing inner routes | <br>|
{{innerProtocol}} | {{Direct}} | The Protocol used internally by the Routebox component. Can
be Direct or SEDA. *The Routebox component currently offers protocols that are JVM bound.*
| <br>| {{sendToConsumer}} | {{true}} | Dictates whether a Producer endpoint sends a
request to an external routebox consumer. If the setting is false, the Producer creates an
embedded inner context and processes requests internally. | <br>| {{forkContext}} |
{{true}} | The Protocol used internally by the Routebox component. Can be Direct or SEDA.
*The Routebox component currently offers protocols that are JVM bound.* | <br>| {{threads}}
| {{20}} | Number of threads to be used by the routebox to receive requests. *Setting applicable
only for innerProtocol SEDA*. | <br>| {{queueSize}} | {{unlimited}} | Create a fixed
size queue to receive requests. *Setting applicable only for innerProtocol SEDA*. | <br>{div}
<br> <br>h3. Sending/Receiving Messages to/from the routebox <br> <br>Before
sending requests it is necessary to properly configure the routebox by loading the required
URI parameters into the Registry as shown below. In the case of Spring, if the necessary beans
are declared correctly, the registry is automatically populated by Camel. <br> <br>h4.
Step 1: Loading inner route details into the Registry  <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">@Override
<br>protected JndiRegistry createRegistry() throws Exception { <br>    JndiRegistry
registry = new JndiRegistry(createJndiContext()); <br> <br>    // Wire the routeDefinitions
&amp; dispatchStrategy to the outer camelContext where the routebox is declared <br>
   List&lt;RouteBuilder&gt; routes = new ArrayList&lt;RouteBuilder&gt;();
<br>    routes.add(new SimpleRouteBuilder()); <br>    registry.bind(&quot;registry&quot;,
createInnerRegistry()); <br>    registry.bind(&quot;routes&quot;, routes); <br>
<br>    // Wire a dispatch map to registry <br>    HashMap&lt;String, String&gt;
map = new HashMap&lt;String, String&gt;(); <br>    map.put(&quot;addToCatalog&quot;,
&quot;seda:addToCatalog&quot;); <br>    map.put(&quot;findBook&quot;,
&quot;seda:findBook&quot;); <br>    registry.bind(&quot;map&quot;, map);
<br> <br>    // Alternatively wiring a dispatch strategy to the registry <br>
   registry.bind(&quot;strategy&quot;, new SimpleRouteDispatchStrategy()); <br>
<br>    return registry; <br>} <br> <br>private JndiRegistry createInnerRegistry()
throws Exception { <br>    JndiRegistry innerRegistry = new JndiRegistry(createJndiContext());
<br>    BookCatalog catalogBean = new BookCatalog(); <br>    innerRegistry.bind(&quot;library&quot;,
catalogBean);         <br> <br>    return innerRegistry; <br>} <br>...
<br>CamelContext context = new DefaultCamelContext(createRegistry()); <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">camelContextId:localEndpointName[?options]
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h4.
Step 2: Optionaly using a Dispatch Strategy instead of a Dispatch Map <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
localEndpoint name can be a valid Camel URI evaluated within the black box CamelContext. Or
it can be a logical name which is mapped to any local endpoints. For example if you locally
have endpoints like *direct:invoices** and **seda:purchaseOrders** inside a CamelContext of
id **supplyChain**, then you can just use the URIs **supplyChain:invoices** or **supplyChain:purchaseOrders**
to omit the physical endpoint kind and use pure logical URIs. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Using
a dispatch Strategy involves implementing the interface _org.apache.camel.component.routebox.strategy.RouteboxDispatchStrategy_
as shown in the example below. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">You
can append query options to the URI in the following format, {{?option=value&amp;option=value&amp;...}}
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code}
<br>public class SimpleRouteDispatchStrategy implements RouteboxDispatchStrategy { <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Example <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
   /* (non-Javadoc) <br>     * @see org.apache.camel.component.routebox.strategy.RouteboxDispatchStrategy#selectDestinationUri(java.util.List,
org.apache.camel.Exchange) <br>     */ <br>    public URI selectDestinationUri(List&lt;URI&gt;
activeDestinations, <br>            Exchange exchange) { <br>        URI dispatchDestination
= null; <br> <br>        String operation = exchange.getIn().getHeader(&quot;ROUTE_DISPATCH_KEY&quot;,
String.class); <br>        for (URI destination : activeDestinations) { <br> 
          if (destination.toASCIIString().equalsIgnoreCase(&quot;seda:&quot; + operation))
{ <br>                dispatchDestination = destination; <br>                break;
<br>            } <br>        } <br> <br>        return dispatchDestination;
<br>    } <br>} <br>{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">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). <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h4.
Step 2: Launching a routebox consumer <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">This
can be done in the usual Camel way from this [test case|http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&amp;view=markup];
this example shows Java and JNDI being used... <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">When
creating a route consumer, note that the # entries in the routeboxUri are matched to the created
inner registry, routebuilder list and dispatchStrategy/dispatchMap in the CamelContext Registry.
Note that all routebuilders and associated routes are launched in the routebox created inner
context <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">private
String routeboxUri = &quot;routebox:multipleRoutes?innerRegistry=#registry&amp;routeBuilders=#routes&amp;dispatchMap=#map&quot;;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">//
lets create our black box as a camel context and a set of routes <br>DefaultCamelContext
blackBox = new DefaultCamelContext(registry); <br>blackBox.setName(&quot;blackBox&quot;);
<br>blackBox.addRoutes(new RouteBuilder() { <br>    @Override <br>    public
void configure() throws Exception { <br>        // receive purchase orders, lets process
it in some way then send an invoice <br>        // to our invoice endpoint <br>
       from(&quot;direct:purchaseOrder&quot;). <br>          setHeader(&quot;received&quot;).constant(&quot;true&quot;).
<br>          to(&quot;direct:invoice&quot;); <br>    } <br>});
<br>blackBox.start(); <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">public
void testRouteboxRequests() throws Exception { <br>    CamelContext context = createCamelContext();
<br>    template = new DefaultProducerTemplate(context); <br>    template.start();
        <br> <br>    context.addRoutes(new RouteBuilder() { <br>       
public void configure() { <br>            from(routeboxUri) <br>             
  .to(&quot;log:Routes operation performed?showAll=true&quot;); <br>       
} <br>    }); <br>    context.start(); <br> <br>    // Now use the
ProducerTemplate to send the request to the routebox <br>    template.requestBodyAndHeader(routeboxUri,
book, &quot;ROUTE_DISPATCH_KEY&quot;, &quot;addToCatalog&quot;); <br>}
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">registry.bind(&quot;accounts&quot;,
blackBox); <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h4.
Step 3: Using a routebox producer <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">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 <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">When
sending requests to the routebox, it is not necessary for producers do not need to know the
inner route endpoint URI and they can simply invoke the Routebox URI endpoint with a dispatch
strategy or dispatchMap as shown below <br> <br>It is necessary to set a special
exchange Header called *ROUTE_DISPATCH_KEY* (optional for Dispatch Strategy) with a key that
matches a key in the dispatch map so that the request can be sent to the correct inner route
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&lt;camelContext
id=&quot;accounts&quot;&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">from(&quot;direct:sendToStrategyBasedRoutebox&quot;)</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;route&gt;</span>
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
   &lt;from uri=&quot;direct:purchaseOrder&quot;/&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">.to(&quot;routebox:multipleRoutes?innerRegistry=#registry&amp;routeBuilders=#routes&amp;dispatchStrategy=#strategy&quot;)</span>
<span class="diff-added-words"style="background-color: #dfd;">...</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
   .to(&quot;log:Routes operation performed?showAll=true&quot;); <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
   &lt;to uri=&quot;direct:invoice&quot;/&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;/route&gt;</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">from
(&quot;direct:sendToMapBasedRoutebox&quot;) <br>    .setHeader(&quot;ROUTE_DISPATCH_KEY&quot;,
constant(&quot;addToCatalog&quot;)) <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">.to(&quot;routebox:multipleRoutes?innerRegistry=#registry&amp;routeBuilders=#routes&amp;dispatchMap=#map&quot;)</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;/camelContext&gt;</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
   .to(&quot;log:Routes operation performed?showAll=true&quot;); <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>Then in another CamelContext we can then refer to this &quot;accounts black
box&quot; by just sending to **accounts:purchaseOrder** and consuming from **accounts:invoice**.
<br> <br>If you prefer to be more verbose and explicit you could use **context:accounts:purchaseOrder**
or even **context:accounts:direct://purchaseOrder** if you prefer. But using logical endpoint
URIs is preferred as it hides the implementation detail and provides a simple logical naming
scheme. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Routebox-ContextComponent"></a>Context Component</h2>

<p><b>Available as of Camel 2.7</b></p>

<p>The <b>context</b> component allows you to create a CamelContext with
a number of routes inside then treat it as a black box and refer to the local endpoints within
the black box from other CamelContexts.</p>

<p>It is similar to the <a href="/confluence/display/CAMEL/Routebox" title="Routebox">Routebox</a>
component, 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).</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-context<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="Routebox-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
context:camelContextId:localEndpointName[?options]
</pre>
</div></div>

<p>Or you can omit the "context:" prefix.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
camelContextId:localEndpointName[?options]
</pre>
</div></div>

<p>The localEndpoint name can be a valid Camel URI evaluated within the black box CamelContext.
Or it can be a logical name which is mapped to any local endpoints. For example if you locally
have endpoints like <b>direct:invoices</b>* and *<b>seda:purchaseOrders</b>*
inside a CamelContext of id *<b>supplyChain</b><b>, then you can just use
the URIs **supplyChain:invoices</b>* or *<b>supplyChain:purchaseOrders</b>*
to omit the physical endpoint kind and use pure logical URIs.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="Routebox-Example"></a>Example</h3>

<p>First you need to create a CamelContext, add some routes in it, start it and then
register the CamelContext into the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>
(JNDI, Spring, Guice or OSGi etc).</p>

<p>This can be done in the usual Camel way from this <a href="http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&amp;view=markup"
class="external-link" rel="nofollow">test case</a>; this example shows Java and JNDI
being used...</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// lets create our black box as a camel context and a set
of routes
</span>DefaultCamelContext blackBox = <span class="code-keyword">new</span>
DefaultCamelContext(registry);
blackBox.setName(<span class="code-quote">"blackBox"</span>);
blackBox.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
    @Override
    <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span>
Exception {
        <span class="code-comment">// receive purchase orders, lets process it in some
way then send an invoice
</span>        <span class="code-comment">// to our invoice endpoint
</span>        from(<span class="code-quote">"direct:purchaseOrder"</span>).
          setHeader(<span class="code-quote">"received"</span>).constant(<span
class="code-quote">"<span class="code-keyword">true</span>"</span>).
          to(<span class="code-quote">"direct:invoice"</span>);
    }
});
blackBox.start();

registry.bind(<span class="code-quote">"accounts"</span>, blackBox);
</pre>
</div></div>

<p>Notice in the above route we are using pure local endpoints (*<b>direct</b>*
and *<b>seda</b><b>). Also note we expose this CamelContext using the **accounts</b>*
ID. We can do the same thing in Spring via</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"accounts"</span>&gt;
  &lt;route&gt; 
    &lt;from uri=<span class="code-quote">"direct:purchaseOrder"</span>/&gt;
    ...
    &lt;to uri=<span class="code-quote">"direct:invoice"</span>/&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;
</pre>
</div></div>

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

<p>If you prefer to be more verbose and explicit you could use *<b>context:accounts:purchaseOrder</b>*
or even *<b>context:accounts:direct://purchaseOrder</b>* if you prefer. But using
logical endpoint URIs is preferred as it hides the implementation detail and provides a simple
logical naming scheme.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Routebox">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24192258&revisedVersion=7&originalVersion=6">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Routebox?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message