HBase Producer - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

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.

hbase://table[?options]

where table is the table name.

The supported operations are:

  • Put

  • Get

  • Delete

  • Scan

Supported URI options on producer

Name

Default Value

Description

operation

CamelHBasePut

The HBase operation to perform. Supported values: CamelHBasePut, CamelHBaseGet, CamelHBaseDelete, and CamelHBaseScan.

maxResults

100

The maximum number of rows to scan. Supported operations: CamelHBaseScan.

mappingStrategyName

header

The strategy to use for mapping Camel messages to HBase columns. Supported values: header, or body.

mappingStrategyClassName

null

The class name of a custom mapping strategy implementation.

filters

null

A list of filters. Supported operations: CamelHBaseScan.

Header mapping options:

Name

Default Value

Description

rowId

 

The id of the row. This has limited use as the row usually changes per Exchange.

rowType

String

The type to covert row id to. Supported operations: CamelHBaseScan.

family

 

The column family. Supports a number suffix for referring to more than one columns

qualifier

 

The column qualifier. Supports a number suffix for referring to more than one columns

value

 

The value. Supports a number suffix for referring to more than one columns

valueType

String

The value type. Supports a number suffix for referring to more than one columns. Supported operations: CamelHBaseGet, and CamelHBaseScan.

Put Operations.

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.

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.

<route>
    <from uri="direct:in"/>
    <!-- Set the HBase Row -->
    <setHeader headerName="CamelHBaseRowId">
        <el>${in.body.id}</el>
    </setHeader>
    <!-- Set the HBase Value -->
    <setHeader headerName="CamelHBaseValue">
        <el>${in.body.value}</el>
    </setHeader>
    <to 
    uri="hbase:mytable?opertaion=CamelHBasePut&amp;family=myfamily&amp;qualifier=
    myqualifier"/>
</route>

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. Notice that you must use numbers from the 2nd header onwards, eg RowId2, RowId3, RowId4, etc. Only the 1st header does not have the number 1.

<route>
    <from uri="direct:in"/>
    <!-- Set the HBase Row 1st column -->
    <setHeader headerName="CamelHBaseRowId">
        <el>${in.body.id}</el>
    </setHeader>
    <!-- Set the HBase Row 2nd column -->
    <setHeader headerName="CamelHBaseRowId2">
        <el>${in.body.id}</el>
    </setHeader>
    <!-- Set the HBase Value for 1st column -->
    <setHeader headerName="CamelHBaseValue">
        <el>${in.body.value}</el>
    </setHeader>
    <!-- Set the HBase Value for 2nd column -->
    <setHeader headerName="CamelHBaseValue2">
        <el>${in.body.othervalue}</el>
    </setHeader>
    <to 
    uri="hbase:mytable?opertaion=CamelHBasePut&amp;family=myfamily&amp;qualifier=
    myqualifier&amp;family2=myfamily&amp;qualifier2=myqualifier2"/>
</route>

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.

Get Operations.

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.

<route>
    <from uri="direct:in"/>
    <!-- Set the HBase Row of the Get -->
    <setHeader headerName="CamelHBaseRowId">
        <el>${in.body.id}</el>
    </setHeader>
    <to 
    uri="hbase:mytable?opertaion=CamelHBaseGet&amp;family=myfamily&amp;qualifier=
    myqualifier&amp;valueType=java.lang.Long"/>
    <to uri="log:out"/>
</route>

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

Delete Operations.

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.

<route>
    <from uri="direct:in"/>
    <!-- Set the HBase Row of the Get -->
    <setHeader headerName="CamelHBaseRowId">
        <el>${in.body.id}</el>
    </setHeader>
    <to uri="hbase:mytable?opertaion=CamelHBaseDelete"/>
</route>

Scan Operations.

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.

<route>
    <from uri="direct:in"/>
    <to uri="hbase:mytable?opertaion=CamelHBaseScan&amp;family=myfamily&amp;
     qualifier=myqualifier&amp;valueType=java.lang.Long&amp;rowType=
     java.lang.String"/>
    <to uri="log:out"/>
</route>

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 ALL the filters.

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.

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.

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

<route>
    <from uri="direct:scan"/>
    <!-- Set the Criteria -->
    <setHeader headerName="CamelHBaseFamily">
        <constant>name</constant>
    </setHeader>
    <setHeader headerName="CamelHBaseQualifier">
        <constant>first</constant>
    </setHeader>
    <setHeader headerName="CamelHBaseValue">
        <el>in.body.firstName</el>
    </setHeader>
    <setHeader headerName="CamelHBaseFamily2">
        <constant>name</constant>
    </setHeader>
    <setHeader headerName="CamelHBaseQualifier2">
        <constant>last</constant>
    </setHeader>
    <setHeader headerName="CamelHBaseValue2">
        <el>in.body.lastName</el>
    </setHeader>
    <!-- Set additional fields that you want to be return by skipping value -->
    <setHeader headerName="CamelHBaseFamily3">
        <constant>address</constant>
    </setHeader>
    <setHeader headerName="CamelHBaseQualifier3">
        <constant>country</constant>
    </setHeader>
    <to uri="hbase:mytable?opertaion=CamelHBaseScan&amp;filters=#myFilterList"/>
</route>
 
<bean id="myFilters" class="java.util.ArrayList">
    <constructor-arg>
        <list>
            <bean class="org.apache.camel.component.hbase.filters.
            ModelAwareColumnMatchingFilter"/>
        </list>
    </constructor-arg>
</bean>

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.