Integration / Apache Camel Interview Questions
How does the Idempotent Consumer EIP work and what idempotent repositories does Camel support?
The Idempotent Consumer deduplicates messages by tracking message IDs in a repository. If a message with the same ID is received again (e.g., after a retry or redelivery), it is silently dropped, ensuring each logical message is processed exactly once.
// In-memory repository (dev/testing):
from("jms:queue:payments")
.idempotentConsumer(header("JMSMessageID"),
MemoryIdempotentRepository.memoryIdempotentRepository(5000))
.to("direct:processPayment");
// JDBC repository (production, survives restarts):
JdbcMessageIdRepository repo =
new JdbcMessageIdRepository(dataSource, "paymentRoute");
from("jms:queue:payments")
.idempotentConsumer(header("JMSMessageID"), repo)
.to("direct:processPayment");
// Infinispan (distributed cache for clusters):
InfinispanIdempotentRepository infinispanRepo = ...
from("kafka:topic:payments?brokers=k:9092")
.idempotentConsumer(header("kafka.KEY"), infinispanRepo)
.to("direct:process");Camel supports multiple idempotent repository implementations: MemoryIdempotentRepository (in-memory, non-persistent), JdbcMessageIdRepository (persistent via JDBC), JpaMessageIdRepository (JPA), InfinispanIdempotentRepository (distributed cache), and HazelcastIdempotentRepository (Hazelcast). The repository stores message IDs for a configurable TTL or indefinitely.
More Related questions...