camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > hbase
Date Wed, 13 Jun 2012 04:36: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/hbase">hbase</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (15)</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" >                &lt;el&gt;${in.body.value}&lt;/el&gt; <br>            &lt;/setHeader&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;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBasePut&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;/route&gt; <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >                &lt;el&gt;${in.body.othervalue}&lt;/el&gt; <br>            &lt;/setHeader&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;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBasePut&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;family2=myfamily&amp;amp;qualifier2=myqualifier2&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;/route&gt; <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >                &lt;el&gt;${in.body.id}&lt;/el&gt; <br>            &lt;/setHeader&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;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBaseGet&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;valueType=java.lang.Long&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >            &lt;to uri=&quot;log:out&quot;/&gt; <br>        &lt;/route&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >                &lt;el&gt;${in.body.id}&lt;/el&gt; <br>            &lt;/setHeader&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;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBaseDelete&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;/route&gt; <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;route&gt; <br>            &lt;from uri=&quot;direct:in&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;">&lt;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBaseScan&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;valueType=java.lang.Long&amp;amp;rowType=java.lang.String&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >            &lt;to uri=&quot;log:out&quot;/&gt; <br>        &lt;/route&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >                &lt;constant&gt;country&lt;/constant&gt; <br>            &lt;/setHeader&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;from</span> <span class="diff-added-words"style="background-color: #dfd;">&lt;to</span> uri=&quot;hbase:mytable?opertaion=CamelHBaseScan&amp;amp;filters=#myFilterList&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;/route&gt; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{mappingStrategyClassName}} | | The class name of a custom mapping strategy implementation| <br>| {{filters}} | | A list of filters. *Supported operations*: CamelHBaseScan | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Header mapping options: <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall} <br></td></tr>
            <tr><td class="diff-unchanged" >|| Name || Default Value || Description || <br>| {{rowId}} |  | The id of the row. This has limited use as the row usually changes per Exchange.| <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{value}} | | The value. Supports a number suffix for referring to more than one columns | <br>| {{rowModel}} | String | An instance of org.apache.camel.component.hbase.model.HBaseRow which describes how each row should be modeled | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>If the role of the rowModel is not clear, it allows you to construct the HBaseRow modle programmatically instead of &quot;describing&quot; it with uri options (such as family, qualifier, type etc). <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >To put the value &quot;myvalue&quot; into HBase row &quot;myrow&quot; and column &quot;myfamily:mycolum&quot; the message should contain the following headers: <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall} <br></td></tr>
            <tr><td class="diff-unchanged" >|| Header || Value || <br>| CamelHBaseRowId | myrow | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| CamelHBaseQualifier | myqualifier | <br>| CamelHBaseValue | myvalue | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>To put more values for different columns and / or different rows you can specify additional headers suffixed with the index of the headers, e.g: <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall} <br></td></tr>
            <tr><td class="diff-unchanged" >|| Header || Value || <br>| CamelHBaseRowId | myrow | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| CamelHBaseQualifier2 | myqualifier | <br>| CamelHBaseValue2 | myvalue2 | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>In the case of retrieval operations such as get or scan you can also specify for each column the type that you want the data to be converted to. For exampe: <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall} <br></td></tr>
            <tr><td class="diff-unchanged" >|| Header || Value || <br>| CamelHBaseFamily | myfamily | <br>| CamelHBaseQualifier | myqualifier | <br>| CamelHBaseValueType | Long | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Please note that in order to avoid boilerplate headers that are considered constant for all messages, you can also specify them as part of the endpoint uri, as you will see below. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="hbase-HBaseComponent"></a>HBase Component</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>This component provides an idemptotent repository, producers and consumers for Apache HBase.</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-hbase<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="hbase-ApacheHBaseOverview"></a>Apache HBase Overview</h3>
<p>HBase is an open-source, distributed, versioned, column-oriented store modeled after Google's Bigtable: A Distributed Storage System for Structured Data. You can use HBase when you need random, realtime read/write access to your Big Data. More information at <a href="http://hbase.apache.org" class="external-link" rel="nofollow">Apache HBase</a>.</p>

<h3><a name="hbase-CamelandHBase"></a>Camel and HBase</h3>
<p>When using a datasotre inside a camel route, there is always the chalenge of specifying how the camel message will stored to the datastore. In document based stores things are more easy as the message body can be directly mapped to a document. In relational databases an ORM solution can be used to map properties to columns etc. In column based stores things are more challenging as there is no standard way to perform that kind of mapping. </p>

<p>HBase adds two additional challenges:</p>
<ul class="alternate" type="square">
	<li>HBase groups columns into families, so just mapping a property to a column using a name convention is just not enough.</li>
	<li>HBase doesn't have the notion of type, which means that it stores everything as byte[] and doesn't know if the byte[] represents a String, a Number, a serialized Java object or just binary data.</li>
</ul>


<p>To overcome these challenges, camel-hbase makes use of the message headers to specify the mapping of the message to HBase columns. It also provides the ability to use some camel-hbase provided classes that model HBase data and can be easily convert to and from xml/json etc.<br/>
Finally it provides the ability to the user to implement and use his own mapping strategy.</p>

<p>Regardless of the mapping strategy camel-hbase will convert a message into an org.apache.camel.component.hbase.model.HBaseData object and use that object for its internal operations.</p>

<h3><a name="hbase-Configuringthecomponent"></a>Configuring the component</h3>

<p>The HBase component can be provided a custom HBaseConfiguration object as a property or it can create an HBase configuration object on its own based on the HBase related resources that are found on classpath.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"hbase"</span> class=<span class="code-quote">"org.apache.camel.component.hbase.HBaseComponent"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"configuration"</span> ref=<span class="code-quote">"config"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div> 

<p>If no configuration object is provided to the component, the component will create one. The created configuration will search the class path for an hbase-site.xml file, from which it will draw the configuration. You can find more information about how to configure HBase clients at: <a href="http://archive.apache.org/dist/hbase/docs/client_dependencies.html" class="external-link" rel="nofollow">HBase client configuration and dependencies </a></p>


<h3><a name="hbase-HBaseProducer"></a>HBase Producer</h3>
<p>As mentioned above camel provides produers endpoints for HBase. This allows you to store, delete, retrieve or query data from HBase using your camel routes.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hbase:[table]
</pre>
</div></div> 

<p>The supported operations are:</p>

<ul class="alternate" type="square">
	<li>Put</li>
	<li>Get</li>
	<li>Delete</li>
	<li>Scan</li>
</ul>


<h4><a name="hbase-SupportedURIoptions"></a>Supported URI options</h4>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>operation</tt> </td>
<td class='confluenceTd'> CamelHBasePut </td>
<td class='confluenceTd'> The HBase operation to perform. <b>Supported values</b>: CamelHbasePut, CamelHBaseGet, CamelHBaseDelete, CamelHBaseScan </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxResults</tt> </td>
<td class='confluenceTd'> 100 </td>
<td class='confluenceTd'> The maximum number of rows to scan.<b>Supported operations</b>: CamelHBaseScan</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mappingStrategyName</tt> </td>
<td class='confluenceTd'> header </td>
<td class='confluenceTd'> The strategy to use for mapping Camel messages to HBase columns. Supported values: header, body</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mappingStrategyClassName</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The class name of a custom mapping strategy implementation</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filters</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> A list of filters. <b>Supported operations</b>: CamelHBaseScan </td>
</tr>
</tbody></table>
</div>


<p>Header mapping options:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>rowId</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The id of the row. This has limited use as the row usually changes per Exchange.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>rowType</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The type to covert row id to. <b>Supported operations</b>: CamelHBaseScan </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>family</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The column family. <b>Supports</b> a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>qualifier</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The column qualifier. <b>Supports</b> a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>value</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The value. <b>Supports</b> a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>valueType</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The value type. <b>Supported operations</b>: CamelHBaseGet &amp; CamelHBaseScan. Supports a number suffix for referring to more than one columns </td>
</tr>
</tbody></table>
</div>



<h4><a name="hbase-PutOperations."></a>Put Operations.</h4>
<p>HBase is a column based store, which allows you to store data into a specific column of a specific row. Columns are grouped into families, so in order to specify a column you need to specify the column family and the qualifier of that column. To store data into a specific column you need to specify both the column and the row.</p>

<p>The simplest scenario for storing data into HBase from a camel route, would be to store part of the message body to specified HBase column.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Row --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseRowId"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.id}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Value --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseValue"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.value}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBasePut&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>The route above assumes that the message body contains an object that has an id and value property and will store the content of value in the HBase column myfamily:myqualifier in the row specified by id. If we needed to specify more than one column/value pairs we could just specify additional column mappings:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Row 1st column --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseRowId"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.id}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Row 2nd column --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseRowId"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.id}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Value for 1st column --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseValue"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.value}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Value for 2nd column --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseValue2"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.othervalue}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBasePut&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;family2=myfamily&amp;amp;qualifier2=myqualifier2"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>It is important to remember that you can use uri options, message headers or a combination of both. It is recommended to specify constants as part of the uri and dynamic values as headers. If something is defined both as header and as part of the uri, the header will be used.</p>

<h4><a name="hbase-GetOperations."></a>Get Operations.</h4>
<p>A Get Operation is an operation that is used to retrieve one or more values from a specified HBase row. To specify what are the values that you want to retrieve you can just specify them as part of the uri or as message headers.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Row of the Get --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseRowId"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.id}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBaseGet&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;valueType=java.lang.Long"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"log:out"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>In the example above the result of the get operation will be stored as a header with name CamelHBaseValue.</p>

<h4><a name="hbase-DeleteOperations."></a>Delete Operations.</h4>
<p>You can also you camel-hbase to perform HBase delete operation. The delete operation will remove an entire row. All that needs to be specified is one or more rows as part of the message headers.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the HBase Row of the Get --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseRowId"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>${in.body.id}<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBaseDelete"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="hbase-ScanOperations."></a>Scan Operations.</h4>
<p>A scan operation is the equivalent of a query in HBase. You can use the scan operation to retrieve multiple rows. To specify what columns should be part of the result and also specify how the values will be converted to objects you can use either uri options or headers.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBaseScan&amp;amp;family=myfamily&amp;amp;qualifier=myqualifier&amp;amp;valueType=java.lang.Long&amp;amp;rowType=java.lang.String"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"log:out"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>In this case its probable that you also also need to specify a list of filters for limiting the results. You can specify a list of filters as part of the uri and camel will return only the rows that satisfy <b>ALL</b> the filters. <br/>
To have a filter that will be aware of the information that is part of the message, camel defines the ModelAwareFilter. This will allow your filter to take into consideration the model that is defined by the message and the mapping strategy.<br/>
When using a ModelAwareFilter camel-hbase will apply the selected mapping strategy to the in message, will create an object that models the mapping and will pass that object to the Filter.</p>

<p>For example to perform scan using as criteria the message headers, you can make use of the ModelAwareColumnMatchingFilter as shown below.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:scan"</span>/&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set the Criteria --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseFamily"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>name<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseQualifier"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>first<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseValue"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>in.body.firstName<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseFamily2"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>name<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseQualifier2"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>last<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseValue2"</span>&gt;</span>
                <span class="code-tag">&lt;el&gt;</span>in.body.lastName<span class="code-tag">&lt;/el&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag"><span class="code-comment">&lt;!-- Set additional fields that you want to be return by skipping value --&gt;</span></span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseFamily3"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>address<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelHBaseQualifier3"</span>&gt;</span>
                <span class="code-tag">&lt;constant&gt;</span>country<span class="code-tag">&lt;/constant&gt;</span>
            <span class="code-tag">&lt;/setHeader&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"hbase:mytable?opertaion=CamelHBaseScan&amp;amp;filters=#myFilterList"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>

        <span class="code-tag">&lt;bean id=<span class="code-quote">"myFilters"</span> class=<span class="code-quote">"java.util.ArrayList"</span>&gt;</span>
            <span class="code-tag">&lt;constructor-arg&gt;</span>
                <span class="code-tag">&lt;list&gt;</span>
                    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.hbase.filters.ModelAwareColumnMatchingFilter"</span>/&gt;</span>
                <span class="code-tag">&lt;/list&gt;</span>
            <span class="code-tag">&lt;/constructor-arg&gt;</span>
        <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>The route above assumes that a pojo is with properties firstName and lastName is passed as the message body, it takes those properties and adds them as part of the message headers. The default mapping strategy will create a model object that will map the headers to HBase columns and will pass that model the the ModelAwareColumnMatchingFilter. The filter will filter out any rows, that do not contain columns that match the model. It is like query by example.</p>

<h3><a name="hbase-HBaseConsumer"></a>HBase Consumer</h3>
<p>The Camel HBase Consumer, will perform repeated scan on the specified HBase table and will return the scan results as part of the message. You can either specify header mapping (default) or body mapping. The later will just add the org.apache.camel.component.hbase.model.HBaseData as part of the message body.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hbase:[table]
</pre>
</div></div> 

<p>You can specify the columns that you want to be return and their types as part of the uri options:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hbase:mutable?family=name&amp;qualifer=first&amp;valueType=java.lang.<span class="code-object">String</span>&amp;family=address&amp;qualifer=number&amp;valueType2=java.lang.<span class="code-object">Integer</span>&amp;rowType=java.lang.<span class="code-object">Long</span>
</pre>
</div></div> 

<p>The example above will create a model object that is consisted of the specified fields and the scan results will populate the model object with values. Finally the mapping strategy will be used to map this model to the camel message.</p>

<h4><a name="hbase-SupportedURIoptions"></a>Supported URI options</h4>

<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>operation</tt> </td>
<td class='confluenceTd'> CamelHBasePut </td>
<td class='confluenceTd'> The HBase operation to perform. <b>Supported values</b>: CamelHbasePut, CamelHBaseGet, CamelHBaseDelete, CamelHBaseScan </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxResults</tt> </td>
<td class='confluenceTd'> 100 </td>
<td class='confluenceTd'> The maximum number of rows to scan. (CamelHBaseScanOnly)</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mappingStrategyName</tt> </td>
<td class='confluenceTd'> header </td>
<td class='confluenceTd'> The strategy to use for mapping Camel messages to HBase columns. Supported values: header, body</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mappingStrategyClassName</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The class name of a custom mapping strategy implementation</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filters</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> A list of filters. <b>Supported operations</b>: CamelHBaseScan </td>
</tr>
</tbody></table>
</div>
</div>

<p>Header mapping options:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>rowId</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The id of the row. This has limited use as the row usually changes per Exchange.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>rowType</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The type to covert row id to. <b>Supported operations</b>: CamelHBaseScan </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>family</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The column family. *upports a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>qualifier</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The column qualifier. *Supports a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>value</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The value. Supports a number suffix for referring to more than one columns </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>rowModel</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> An instance of org.apache.camel.component.hbase.model.HBaseRow which describes how each row should be modeled </td>
</tr>
</tbody></table>
</div>
</div>

<p>If the role of the rowModel is not clear, it allows you to construct the HBaseRow modle programmatically instead of "describing" it with uri options (such as family, qualifier, type etc).</p>

<h3><a name="hbase-HBaseIdempotentrepository"></a>HBase Idempotent repository</h3>

<p>The camel-hbase component also provides an idempotent repository which can be used when you want to make sure that each message is processed only once. The HBase idempotent repository is configured with a table, a column family and a column qualifier and will create to that table a row per message.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HBaseConfiguration configuration = HBaseConfiguration.create();
HBaseIdempotentRepository repository = <span class="code-keyword">new</span> HBaseIdempotentRepository(configuration, tableName, family, qualifier);
from(<span class="code-quote">"direct:in"</span>).idempotentConsumer(header(<span class="code-quote">"messageId"</span>), repository).to("log:out);
</pre>
</div></div>

<h3><a name="hbase-HBaseMapping"></a>HBase Mapping</h3>
<p>It was mentioned above that you the default mapping strategies are <b>header</b> and <b>body</b> mapping.<br/>
Below you can find some detailed examples of how each mapping strategy works.</p>

<h4><a name="hbase-HBaseHeadermappingExamples"></a>HBase Header mapping Examples</h4>
<p>The header mapping is the default mapping.<br/>
To put the value "myvalue" into HBase row "myrow" and column "myfamily:mycolum" the message should contain the following headers:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseRowId </td>
<td class='confluenceTd'> myrow </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseFamily </td>
<td class='confluenceTd'> myfamily </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseQualifier </td>
<td class='confluenceTd'> myqualifier </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseValue </td>
<td class='confluenceTd'> myvalue </td>
</tr>
</tbody></table>
</div>
</div>

<p>To put more values for different columns and / or different rows you can specify additional headers suffixed with the index of the headers, e.g:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseRowId </td>
<td class='confluenceTd'> myrow </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseFamily </td>
<td class='confluenceTd'> myfamily </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseQualifier </td>
<td class='confluenceTd'> myqualifier </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseValue </td>
<td class='confluenceTd'> myvalue </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseRowId2 </td>
<td class='confluenceTd'> myrow2 </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseFamily2 </td>
<td class='confluenceTd'> myfamily </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseQualifier2 </td>
<td class='confluenceTd'> myqualifier </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseValue2 </td>
<td class='confluenceTd'> myvalue2 </td>
</tr>
</tbody></table>
</div>
</div>

<p>In the case of retrieval operations such as get or scan you can also specify for each column the type that you want the data to be converted to. For exampe:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Value </th>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseFamily </td>
<td class='confluenceTd'> myfamily </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseQualifier </td>
<td class='confluenceTd'> myqualifier </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHBaseValueType </td>
<td class='confluenceTd'> Long </td>
</tr>
</tbody></table>
</div>
</div>

<p>Please note that in order to avoid boilerplate headers that are considered constant for all messages, you can also specify them as part of the endpoint uri, as you will see below.</p>

<h4><a name="hbase-BodymappingExamples"></a>Body mapping Examples</h4>
<p>In order to use the body mapping strategy you will have to specify the option mappingStrategy as part of the uri, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
hbase:mytable?mappingStrategy=body
</pre>
</div></div>

<p>To use the body mapping strategy the body needs to contain an instance of org.apache.camel.component.hbase.model.HBaseData. You can construct t</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HBaseData data = <span class="code-keyword">new</span> HBaseData();
HBaseRow row = <span class="code-keyword">new</span> HBaseRow();
row.setId(<span class="code-quote">"myRowId"</span>);
HBaseCell cell = <span class="code-keyword">new</span> HBaseCell();
cell.setFamily(<span class="code-quote">"myfamily"</span>);
cell.setQualifier(<span class="code-quote">"myqualifier"</span>);
cell.setValue(<span class="code-quote">"myValue"</span>);
row.getCells().add(cell);
data.addRows().add(row);
</pre>
</div></div>

<p>The object above can be used for example in a put operation and will result in creating or updating the row with id myRowId and add the value myvalue to the column myfamily:myqualifier.<br/>
The body mapping strategy might not seem very appealing at first. The advantage it has over the header mapping strategy is that the HBaseData object can be easily converted to or from xml/json.</p>


<h3><a name="hbase-Seealso"></a>See also</h3>
<ul class="alternate" type="square">
	<li><a href="http://hbase.apache.org" class="external-link" rel="nofollow">Apache HBase</a></li>
</ul>

    </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/hbase">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27849301&revisedVersion=2&originalVersion=1">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/hbase?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message