camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Binding
Date Fri, 19 Oct 2012 10:03:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/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/Binding">Binding</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~jstrachan">James
Strachan</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h1. Binding <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >In Camel terms a _binding_ is
a way of wrapping an [Endpoint] in a contract; such as a [Data Format], a <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[Transformation]</span>
<span class="diff-added-words"style="background-color: #dfd;">[Content Enricher]</span>
or validation step. Bindings are completely optional and you can choose to use them on any
[camel endpoint|Components]. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >Bindings are inspired by the work
of [SwitchYard <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">project](http://www.jboss.org/switchyard)</span>
<span class="diff-added-words"style="background-color: #dfd;">project|http://www.jboss.org/switchyard]</span>
adding service contracts to various technologies like Camel and many others. But rather than
the SwitchYard approach of wrapping Camel in SCA, _Camel Bindings_ provide a way of wrapping
Camel endpoints with contracts inside the Camel framework itself; so you can use them easily
inside any Camel route. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Using Bindings <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="Binding-Binding"></a>Binding</h1>

<p>In Camel terms a <em>binding</em> is a way of wrapping an <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> in a contract; such as a <a href="/confluence/display/CAMEL/Data+Format"
title="Data Format">Data Format</a>, a <a href="/confluence/display/CAMEL/Content+Enricher"
title="Content Enricher">Content Enricher</a> or validation step. Bindings are completely
optional and you can choose to use them on any <a href="/confluence/display/CAMEL/Components"
title="Components">camel endpoint</a>.</p>

<p>Bindings are inspired by the work of <a href="http://www.jboss.org/switchyard"
class="external-link" rel="nofollow">SwitchYard project</a> adding service contracts
to various technologies like Camel and many others. But rather than the SwitchYard approach
of wrapping Camel in SCA, <em>Camel Bindings</em> provide a way of wrapping Camel
endpoints with contracts inside the Camel framework itself; so you can use them easily inside
any Camel route.</p>

<h2><a name="Binding-UsingBindings"></a>Using Bindings</h2>

<p>A Binding is currently a bean which defines the contract (though we'll hopefully
add bindings to the Camel DSL). </p>

<p>There are a few approaches to defining a bound endpoint (i.e. an endpoint bound with
a Binding). </p>

<h3><a name="Binding-UsingthebindingURI"></a>Using the binding URI</h3>

<p>You can prefix any endpoint URI with <b>binding:nameOfBinding:</b> where
<em>nameOfBinding</em> is the name of the Binding bean in your registry. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"binding:jaxb:activemq:myQueue"</span>).to(<span
class="code-quote">"binding:jaxb:activemq:anotherQueue"</span>)
</pre>
</div></div>

<p>Here we are using the "jaxb" binding which may, for example, use the JAXB <a href="/confluence/display/CAMEL/Data+Format"
title="Data Format">Data Format</a> to marshal and unmarshal messages.</p>

<h3><a name="Binding-UsingaBindingComponent"></a>Using a BindingComponent</h3>

<p>There is a <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
called BindingComponent which can be configured in your <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> by dependency injection which allows the creation of
endpoints which are already bound to some binding.</p>

<p>For example if you registered a new component called "jsonmq" in your registry using
code like this</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        JacksonDataFormat format = <span class="code-keyword">new</span> JacksonDataFormat(MyBean.class);
        context.bind(<span class="code-quote">"jsonmq"</span>, <span class="code-keyword">new</span>
BindingComponent(<span class="code-keyword">new</span> DataFormatBinding(format),
<span class="code-quote">"activemq:foo."</span>));
</pre>
</div></div>

<p>Then you could use the endpoint as if it were any other endpoint.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jsonmq:myQueue"</span>).to(<span class="code-quote">"jsonmq:anotherQueue"</span>)
</pre>
</div></div>
<p>which would be using the queueus "foo.myQueue" and "foo.anotherQueue" and would use
the given Jackson <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> to marshal on and off the queue.</p>

<h2><a name="Binding-WhentouseBindings"></a>When to use Bindings</h2>

<p>If you only use an endpoint once in a single route; a binding may actually be more
complex and more work than just using the 'raw' endpoint directly and using explicit marshalling
and validation in the camel route as normal.</p>

<p>However bindings can help when you are composing many routes together; or using a
single route as a 'template' that is configured input and output endpoints; bindings then
provide a nice way to wrap up a contract and endpoint together. </p>

<p>Another good use case for bindings is when you are using many endpoints which use
the same binding; rather than always having to mention a specific data format or validation
rule, you can just use the BindingComponent to wrap the endpoints in the binding of your choice.</p>

<p>So bindings are a composition tool really; only use them when they make sense - the
extra complexity may not be worth it unless you have lots of routes or endpoints.</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/Binding">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30739747&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Binding?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message