Deepak Chaudhary
Deepak Chaudhary

Reputation: 162

Spring Cloud Stream 3.x - replay message strategy

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.

Upvotes: 1

Views: 568

Answers (1)

Gary Russell
Gary Russell

Reputation: 174759

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.

Upvotes: 2

Related Questions