Examples - 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

An example of using camel avro producers via http:

<route>
    <from uri="direct:start"/>
    <to uri="avro:http:localhost:{{avroport}}?protocolClassName=
    org.apache.camel.avro.generated.KeyValueProtocol"/>
    <to uri="log:avro"/>
</route>

In the example above you need to fill CamelAvroMessageName header. Since 2.12 you can use following syntax to call constant messages:

<route>
    <from uri="direct:start"/>
    <to uri="avro:http:localhost:{{avroport}}/put?protocolClassName=
    org.apache.camel.avro.generated.KeyValueProtocol"/>
    <to uri="log:avro"/>
</route>

An example of consuming messages using camel avro consumers via netty:

<route>
    <from uri="avro:netty:localhost:{{avroport}}?protocolClassName=
    org.apache.camel.avro.generated.KeyValueProtocol"/>
    <choice>
        <when>
            <el>${in.headers.CamelAvroMessageName == 'put'}</el>
            <process ref="putProcessor"/>
        </when>
        <when>
            <el>${in.headers.CamelAvroMessageName == 'get'}</el>
            <process ref="getProcessor"/>
        </when>
    </choice>
</route>

Since 2.12 you can set up two distinct routes to perform the same task:

<route>
    <from uri="avro:netty:localhost:{{avroport}}/put?protocolClassName=
    org.apache.camel.avro.generated.KeyValueProtocol">
    <process ref="putProcessor"/></route>
<route>
    <from uri="avro:netty:localhost:{{avroport}}/get?protocolClassName=
    org.apache.camel.avro.generated.KeyValueProtocol&singleParameter=true"/>
    <process ref="getProcessor"/>
</route>  

In the example above, get takes only one parameter, so singleParameter is used and getProcessor will receive Value class directly in body, while putProcessor will receive an array of size 2 with String key and Value value filled as array contents.