설 명절이 지나고 다시 회사 컴퓨터로 kafka를 실행시켰습니다.
근데 전 주 까지만 해도 됐던 것이 갑자기 아래와 같은 에러를 출력되었습니다....
PS C:\Users\DEV\Documents\Go\sarama-master\examples\http_server> go run http_server.go -addr=":8080" -brokers="localhost:9092" -verbose=true -certificate="" -key="" -ca="" -verify=false
[sarama] 2021/02/16 13:55:33 client/metadata retrying after 250ms... (3 attempts remaining)
[sarama] 2021/02/16 13:55:33 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:33 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:33 client/metadata retrying after 250ms... (2 attempts remaining)
[sarama] 2021/02/16 13:55:33 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:33 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:33 client/metadata retrying after 250ms... (1 attempts remaining)
[sarama] 2021/02/16 13:55:33 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:33 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:33 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:33 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:33 client/metadata retrying after 250ms... (3 attempts remaining)
[sarama] 2021/02/16 13:55:34 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:34 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:34 client/metadata retrying after 250ms... (2 attempts remaining)
[sarama] 2021/02/16 13:55:34 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:34 client/metadata found some partitions to be leaderless
[sarama] 2021/02/16 13:55:34 client/metadata retrying after 250ms... (1 attempts remaining)
[sarama] 2021/02/16 13:55:34 client/metadata fetching metadata for [cbsong] from broker localhost:9092
[sarama] 2021/02/16 13:55:34 client/metadata found some partitions to be leaderless
2021/02/16 13:55:34 Failed to write access log entry: kafka: Failed to produce message to topic cbsong: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes.
혹시나 싶어 consumer로 접속을 해보았는데 다음과 같은 출력이 밀리초? 단위로 계속 출력되었습니다.
[2021-02-16 14:03:38,172] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
[2021-02-16 14:03:38,284] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
[2021-02-16 14:03:38,396] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
[2021-02-16 14:03:38,505] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
[2021-02-16 14:03:38,892] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
[2021-02-16 14:03:39,006] WARN [Consumer clientId=consumer-console-consumer-41538-1, groupId=console-consumer-41538] 1 partitions have leader brokers without a matching listener, including [cbsong-0] (org.apache.kafka.clients.NetworkClient)
여기서 부터 삽질이 또 시작되었는데
처음에는 저게 어떤 에러인지 몰라서 해메이고 있었는데 예제 코드의 errors.go에서
case ErrLeaderNotAvailable:
return "kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes."
이 부분에서 걸린다는걸 알아냈습니다.
github.com/Shopify/sarama/blob/master/errors.go
Shopify/sarama
Sarama is a Go library for Apache Kafka 0.8, and up. - Shopify/sarama
github.com
그래서 C:\kafka_2.12-2.4.0\config 경로에 있는 server.property를 수정해야 했었는데
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://your.host.name:9092
에서 맨 아랫줄인 your.host.name:9092 부분의 주석을 풀어주면 된다해서 저 부분의 주석을 풀어주고 아래와 같이 수정해주었습니다.
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://localhost:9092
그 후 kafka를 재시작 해주기 위해 주키퍼 - kafka 순으로 재시작 해주었습니다.
그 후 다시 consumer로 접속을 해보았는데 위와 같은 문구가 계속 출력되었습니다.
혹시나 싶어 Go를 실행 시켰음에도 결과는 마찬가지였습니다.
무엇이 문제일까 싶어 토픽에서 에러가 생겼나 싶어 토픽을 삭제해보았습니다. (이거 삭제하는데도 삽질했습니다...)
zookeeper-shell을 이용하여 삭제를 해야 했습니다.
그러지 않으면
c:\kafka_2.12-2.4.0\bin\windows>kafka-topics.bat --list --zookeeper localhost:2181
__consumer_offsets
cbsong - marked for deletion
이러한 문구에 휩싸이게 될 것입니다...
저렇게 되면 데이터도 전송되지 않고, 같은 이름의 토픽을 생성할 수도 없게 되는 상황이 생기게 됩니다.
해결 방법은 먼저 server.property에 들어가서 아래의 코드를 추가 시켜 줍시다.
delete.topic.enable = true
그 후 Zookeeper 쉘을 이용하여 삭제해주면 되는데
먼저 cmd창에서 kafka폴더\bin\windows로 이동한 다음
$ zookeeper-shell localhost:2181
을 입력해준다. 그러면 아래와 같은 화면이 뜰텐데 제대로 접속 된 것입니다.
그 다음
ls /brokers/topics
을 입력하면 현재 만들어진 토픽 이름이 뜰 것입니다.
확인 후
rmr /brokers/topics/토픽이름
을 입력하면 해당 토픽이름이 정상적으로 삭제되는 것을 알 수 있습니다.
처음에 이런 문구들이 떠서
ls /brokers/topics
[__consumer_offsets, cbsong]
rmr /brokers/topics/__consumer_offsets
The command 'rmr' has been deprecated. Please use 'deleteall' instead.
rmr /brokers/topics/cbsong
The command 'rmr' has been deprecated. Please use 'deleteall' instead.
뭐지 싶었는데 주키퍼 - kafka 순으로 재시작 후 토픽을 조회 해보니 사라진 것을 확인했습니다.
그 후 다시 토픽을 생성 해주면 됩니다.
생성은
kafka폴더\bin\windows>kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic [topicname]
이렇게 해주면 됩니다.
그 후 cosumer로 접속 하면 정상적으로 데이터를 가져 오는 것을 확인 할 수 있습니다.
'프로그래밍(Web) > 업무관련' 카테고리의 다른 글
[바미] 고통스런 yarn build (0) | 2021.03.19 |
---|---|
[바미] Golang Kafka(sarama) + negroni 연동완료. (0) | 2021.02.23 |
[바미] Golang sarama 연동하기(http_server) (0) | 2021.02.09 |
[바미] Golang sarama예제로 Kafka 연동하기(interceptors). (0) | 2021.02.09 |
[바미] 카프카 Invalid config, exiting abnormally에러 대처하기 (0) | 2021.02.09 |