1
votes

I am looking for some guidance around replay message strategy from a Kafka topic utilizing Spring Cloud Stream 3.x / Kafka binder implementations -

  1. Replay specific messages [ for ex. by timestamp window ] from a topic. How to reset offsets for all or some consumers within a consumer group?

  2. Is it possible to replay from a specific partition of the topic [ if we know partitions for messages we are interested in replaying ]?

In general, what are the best practices around message replay. Thank you for your time.

1

1 Answers

2
votes

Add a rebalance listener bean and it will be wired into the binder...

@Bean
KafkaBindingRebalanceListener rebal() {
    return new KafkaBindingRebalanceListener() {

        @Override
        public void onPartitionsAssigned(String bindingName, Consumer<?, ?> consumer,
                Collection<TopicPartition> partitions, boolean initial) {

            consumer.seekToBeginning(partitions);
        }

    };
}

You can use any consumer seek operation; you can also call consumer.offsetsForTimes(...) etc.

The initial flag is true for the first rebalance, false, for others.