먼저 해당 group_id가 존재하는지 확인
./kafka-consumer-groups --bootstrap-server=localhost:9092 --describe --group my-group
offset이 665로 되어 있어, 이전 데이터는 읽을수 없는 상태
offset을 0(to-earliest)으로 셋팅하려고 하려 한다.
kafka-consumer-groups.sh --bootstrap-server <KAFKA_HOST:PORT> --group <GROUP_ID> --topic <TOPIC_NAME> --reset-offsets <옵션> --execute
$ kafka-consumer-groups --bootstrap-server localhost:29092 --group my-group --topic my-topic --reset-offsets --to-earliest --execute
Error: Assignments can only be reset if the group 'my-group' is inactive, but the current state is Stable.
이 에러는 오프셋을 초기화하려는 컨슈머 그룹(my-group)에 아직 연결된 컨슈머가 실행 중이기 때문에 발생한다.
카프카는 데이터의 일관성과 안정성을 보장하기 위해, 컨슈머가 활발히 활동 중인 Stable 상태일 때는 외부에서 오프셋을 강제로 변경하는 것을 허용하지 않는다.
1. 컨슈머 그룹 상태 확인
./kafka-consumer-groups.sh --bootstrap-server localhost:29092 --describe --group my-group
현재 my-group의 컨슈머가 activate 상태이다.
컨슈머를 종료하고 다시 명령어를 해보면
Consumer group 'my-group' has no active members.
이렇게 동작중인 컨슈머 그룹이 없다고 나온다.
2. 컨슈머 애플리케이션 중지
모든 파이썬 스크립트, 자바 애플리케이션 등 모든 컨슈머 프로세스를 찾아 완전히 종료 후 다시 offset을 셋팅한다.
--to-earliest 값은 offset을 가장 처음으로 셋팅해준다.
kafka-consumer-groups --bootstrap-server localhost:29092 --group <그룹id> --topic <토픽> --reset-offsets --to-earliest --execute
다시 상태 확인을 해보면 current-offset이 0으로 셋팅되어 있는것을 볼수 있다.
kafka-consumer-groups --bootstrap-server localhost:29092 --describe --group my-group
원하는 offset 값이 있다면
예를 들어 100번으로 하고 싶다면 --to-offset 100 이런 형식으로 하면 된다.
kafka-consumer-groups --bootstrap-server localhost:29092 --group <그룹id> --topic <토픽> --reset-offsets --to-offset <원하는 offset값> --execute
'server > kafka' 카테고리의 다른 글
ELK 실습 (0) | 2025.04.28 |
---|---|
kafka -> fluentd -> kafka 로 데이터 전송하기 (local) (0) | 2025.03.19 |