...
This pattern is implemented using the IdempotentConsumer class. This uses an Expression to calculate a unique message ID string for a given message exchange; this ID can then be looked up in the MessageIdRepository to see if it has been seen before; if it has the message is consumed; if its not then the message is processed and the ID is added to the repository.
...
Wiki Markup |
---|
{snippet:id=idempotent|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java} |
The above example will use an in-memory based MessageIdRepository which can easily run out of memory and doesn't work in a clustered environment. So you might prefer to use the JPA based implementation which uses a database to store the message IDs which have been processed
Wiki Markup |
---|
{snippet:id=idempotent|lang=java|url=activemq/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaIdempotentConsumerTest.java} |
In the above example we are using the header messageId to filter out duplicates and using the collection myProcessorName to indicate the Message ID Repository to use. This name is important as you could process the same message by many different processors; so each may require its own logical Message ID Repository.
...
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/xml/buildCustomProcessorWithFilter.xml} |
For further examples of this pattern in use you could look at the junit test case
Include Page | ||||
---|---|---|---|---|
|