How to Empty Cache memoryIdempotentRepository in Apache Camel (DSL Java)
Join the DZone community and get the full member experience.
Join For FreeIn this article, we provide a brief tutorial on how to clear the cache memoryIdempotentRepository
in an Apache Camel Application.
The Enterprise Integration Pattern (EIP) IdempotentConsumer
implemented by Apache Camel filters out duplicate exchange messages. This process requires cache. Camel implements different kinds of cache, such as the MemoryIdempotentRepository
[1].
The MemoryIdempotentRepository
is a very fast in-memory store that stores entries in a map structure. Data will be lost when the JVM shuts down. However, it may be the case that you want to delete the cache before or without shutting down the JVM.
To clear the cache you can use clear()
defined in MemoryIdempotentRepository.java.
The following processor clears a MemoryIdempotentRepository
(here named TEMP_CACHE
):
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
TEMP_CACHE.clear();
}
})
[1] https://camel.apache.org/manual/latest/idempotentConsumer-eip.html..
Further Reading
Opinions expressed by DZone contributors are their own.
Comments