camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Context
Date Thu, 10 Feb 2011 16:47: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/Context">Context</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~jstrachan">James
Strachan</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >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> <br></td></tr>
            <tr><td class="diff-changed-lines" >This can be done in the usual
Camel way from this [test <span class="diff-changed-words">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]<span
class="diff-added-chars"style="background-color: #dfd;"> (see the createRegistry() method)</span>;</span>
this example shows Java and JNDI being used... <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Notice in the above route we are
using pure local endpoints <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">(**direct**</span>
<span class="diff-added-words"style="background-color: #dfd;">(*direct*</span>
and <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**seda**).</span>
<span class="diff-added-words"style="background-color: #dfd;">*seda*).</span>
Also note we expose this CamelContext using the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**accounts**</span>
<span class="diff-added-words"style="background-color: #dfd;">*accounts*</span>
ID. We can do the same thing in Spring via <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Then in another CamelContext we
can then refer to this &quot;accounts black box&quot; by just sending to <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**accounts:purchaseOrder**</span>
<span class="diff-added-words"style="background-color: #dfd;">*accounts:purchaseOrder*</span>
and consuming from <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**accounts:invoice**.</span>
<span class="diff-added-words"style="background-color: #dfd;">*accounts:invoice*.</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >If you prefer to be more verbose
and explicit you could use <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**context:accounts:purchaseOrder**</span>
<span class="diff-added-words"style="background-color: #dfd;">*context:accounts:purchaseOrder*</span>
or even <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">**context:accounts:direct://purchaseOrder**</span>
<span class="diff-added-words"style="background-color: #dfd;">*context:accounts:direct://purchaseOrder*</span>
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="Context-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="Context-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>

<ul>
	<li><b>camelContextId</b> is the ID you used to register the CamelContext
into the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</li>
	<li><b>localEndpointName</b> 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>, then you can just use the URIs
<b>supplyChain:invoices</b> or <b>supplyChain:purchaseOrders</b> to
omit the physical endpoint kind and use pure logical URIs.</li>
</ul>


<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="Context-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> (see the createRegistry() method);
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>). Also note we expose this CamelContext using the <b>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/Context">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=25201345&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Context?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message