i am working on springboot with Apache Camel so my question is how can i write code to use Idempotentconsumer with JDBC repository using apache camel.
Asked
Active
Viewed 1,886 times
1 Answers
2
All you need to do is implement
#queryForInt(T key)
#insert(T key)
#delete(T key)
methods of AbstractJdbcMessageIdRepository
from camel-sql
define your bean
<bean id="idempotentRepository"
class="yourpackage.YourJDBCIdempotentRepository">
<property name="dataSource" ref="your-datasource-bean-ref"/>
</bean>
add in route
<route id="your-route">
<from uri="ftp:your-endpoint?idempotent=true&idempotentRepository=#idempotentRepository"/>
...
</route>

Sagar
- 818
- 1
- 6
- 13
-
Would using the standard JdbcMessageIdRepository also work in a distributed environment with multiple nodes? If I look at the "Idempotent Consumer" Camel page (https://camel.apache.org/idempotent-consumer.html) I can see that HazelcastIdempotentRepository works in a clustered environment, but is this also the caser the JdbcMessageIdRepository? When looking at the code of this component in GitHub i cannot see any lock statements (or whatever) to guarantee synchronized access? If anybody can confirm this that would be great! – Kim Zeevaarders May 20 '19 at 13:57
-
@KimZeevaarders - I guess you should try it out. There is some unique constraint you have to add to the camel_messageprocessed table (if using jdbc repo) - see the doco. Seems to work well though. – gurpal2000 Mar 13 '20 at 21:52