Kafka 0.11 how to reset offsets

By default, --reset-offsets just prints the result of the operation. To actually perform the operation you need to add --execute to your command:

kafka-consumer-groups.bat --bootstrap-server kafka-host:9092 --group
my-group --reset-offsets --to-earliest --all-topics --execute

Though the accepted answer perfectly answers OP question, there are more parameters available to reset offsets. So adding this answer to extend accepted answer.

To reset offset of all topics to earliest in the consumer group

kafka-consumer-groups.sh --bootstrap-server <kafka_broker_host:9091> --group
    <group_name> --reset-offsets --to-earliest --all-topics --execute

To reset offset of specific topic to earliest in the consumer group

kafka-consumer-groups.sh --bootstrap-server <kafka_broker_host:9091> --group
    <group_name> --reset-offsets --to-earliest --topic <my-topic> --execute

To reset offset of specific topic to specific offset in the consumer group

kafka-consumer-groups.sh --bootstrap-server <kafka_broker_host:9091> --group
    <group_name> --reset-offsets --to-offset 1000 --topic <my-topic> --execute

Other supported arguments:

--shift-by [positive or negative integer] - Shifts offset forward or backward from given integer.

--to-current and --to-latest are same as --to-offset and --to-earliest.

--to-datetime [Datetime format is yyyy-MM-ddTHH:mm:ss.xxx]

kafka-consumer-groups.sh --bootstrap-server <kafka_broker_host:9091> --group
    <group_name> --reset-offsets --to-datetime 2017-08-04T00:00:00.000 [ --all-topics or --topic <topic-name> ] --execute

--by-duration [Format is PnDTnHnMnS]

kafka-consumer-groups.sh --bootstrap-server <kafka_broker_host:9091> --group
    <group_name> --reset-offsets --by-duration PT0H10M0S [ --all-topics or --topic <topic-name> ] --execute

Reset to offset by duration from current timestamp.

How to validate?

Use below command to check current/end of offsets and to confirm reset made the cahnges.

kafka-consumer-groups.sh --bootstrap-server <kafka_host:port> --group <group_id> --describe

Sample output:

Consumer group 'group1' has no active members.

TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID     HOST            CLIENT-ID
intro           0          0               99              99              -               -               -

Possible Errors:

Error: Assignments can only be reset if the group '[group_name]' is inactive, but the current state is Stable.

'Stable' means, there is an active consumer running for this group. So first you have to stop the active consumer(s) and retry resetting offsets.

It is not possible to reset offsets if there is an active consumer for the consumer group.

Tags:

Apache Kafka