Using the JDBC based idempotent repository - 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

Available as of Camel 2.7: In this section we will use the JDBC based idempotent repository.

From Camel 2.9 onwards there is an abstract class org.apache.camel.processor.idempotent.jdbc.AbstractJdbcMessageIdRepository you can extend to build custom JDBC idempotent repository.

First we have to create the database table which will be used by the idempotent repository. For Camel 2.7, we use the following schema:

CREATE TABLE CAMEL_MESSAGEPROCESSED (
  processorName VARCHAR(255),
  messageId VARCHAR(100)
)

In Camel 2.8, we added the createdAt column:

CREATE TABLE CAMEL_MESSAGEPROCESSED (
  processorName VARCHAR(255),
  messageId VARCHAR(100),
  createdAt TIMESTAMP
)

The SQL Server TIMESTAMP type is a fixed-length binary-string type. It does not map to any of the JDBC time types: DATE, TIME, or TIMESTAMP.

We recommend to have a unique constraint on the columns processorName and messageId. Because the syntax for this constraint differs for database to database, we do not show it here.

Second we need to setup a javax.sql.DataSource in the spring XML file:

<jdbc:embedded-database id="dataSource" type="DERBY" />

And we can create our JDBC idempotent repository in the Spring XML file as well:

<bean id="messageIdRepository" class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
    <constructor-arg ref="dataSource" />
    <constructor-arg value="myProcessorName" />
</bean>
 
<camel:camelContext>
    <camel:errorHandler id="deadLetterChannel" type="DeadLetterChannel" deadLetterUri="mock:error">
        <camel:redeliveryPolicy maximumRedeliveries="0" maximumRedeliveryDelay="0" logStackTrace="false" />
    </camel:errorHandler>
     
    <camel:route id="JdbcMessageIdRepositoryTest" errorHandlerRef="deadLetterChannel">
        <camel:from uri="direct:start" />
        <camel:idempotentConsumer messageIdRepositoryRef="messageIdRepository">
            <camel:header>messageId</camel:header>
            <camel:to uri="mock:result" />
        </camel:idempotentConsumer>
    </camel:route>
</camel:camelContext>