How to do message filtering at Kafka record level when using SpringCloudStream?

Viewed 419

I am using Spring Cloud Stream (SCS) with Kafka as a binder.

I would like to do low-level filtering on records based on the Kafka header. What would be the recommended approach?

The filtered message should be ignored and the offset should be committed.

I was thinking about configuring a RecordFilterStrategy.

1 Answers

RecordFilterStrategy is not supported by Spring Cloud Stream.

You can add ListenerContainerCustomizer bean example here and add a RecordInterceptor to the listener container. If the interceptor returns null, the listener is not called and the offset will be committed, as if the listener was called and exited normally.

Related