user1372217
user1372217

Reputation: 53

Camel route - Filter all but first message

Can I filter messages so only one with a given correlation expression is forwarded?

I have a stream of messages from different devices. I want to keep an SQL table with all devices already encountered.

Trivial way would be to route all messages to an sql component with an insert statement. But this would create unnecessary load on the DB because devices send with a high frequency.

My current solution is to have a java predicate that returns true the first time the device id is encountered since last restart.

This works, but I would like to see if I can replace this with camel on-board methods - potentially making the route easier to understand.

Is there some way to use aggregation to only pass the first message with a given correlation value?

Upvotes: 0

Views: 192

Answers (1)

burki
burki

Reputation: 7025

There is the Camel idempotent consumer that does exactly this.

With the help of a repository of already processed messages it drops any further message with the same identification characteristics.

This is very handy wherever you have at-least-once semantics on message delivery.

Upvotes: 1

Related Questions