yeomko22 / TIL

Today I learned
1 stars 0 forks source link

kafka command line tool #106

Open yeomko22 opened 3 years ago

yeomko22 commented 3 years ago

카프카 토픽

토픽 생성 2가지 방법

토픽 생성시 주의할 점

yeomko22 commented 3 years ago

토픽 생성

$ bin/kafka-topics.sh \
-- create \
--bootstrap-server my-kafka:9092 \
--topic hello.kafka
$ bin/kafka-topics.sh \
--create \
--bootstrap-server my-kafka:9092 \
--partitions 3 \
--replication-factor 1 \
--config retention.ms=172800000 \
--topic hello.kafka.2

생성된 토픽 조회

$ bin/kafka-topics.sh --bootstrap-server my-kafka:9092 --describe --topic hello.kafka.2

토픽 옵션 수정

$ bin/kafka-topics.sh --bootstrap-server my-kafka:9092 \
--topic hello.kafka \
--alter \
--partitions 4
$ bin/kafka-configs.sh --bootstrap-server my-kafka:9092 \
> --entity-type topics \
> --entity-name hello.kafka \
> --alter --add-config retention.ms=865400000
yeomko22 commented 3 years ago

kafka-console-producer

$  bin/kafka-console-producer.sh --bootstrap-server my-kafka:9092 \
> --topic hello.kafka
> --property "parse.key=true" \
> --property "key.separator=:"
yeomko22 commented 3 years ago

kafka-console-consumer

bin/kafka-console-consumer.sh --bootstrap-server my-kafka:9092 \
> --topic hello.kafka \
> --property print.key=true \
> --property key.separator="-" \
> --group hello-group \
> --from-beginning
yeomko22 commented 3 years ago

kafka-consumer-groups.sh

bin/kafka-consumer-groups.sh --bootstrap-server my-kafka:9092 \
> --group hello-group \
> --describe

Consumer group 'hello-group' has no active members.

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID     HOST            CLIENT-ID
hello-group     hello.kafka     3          1               1               0               -               -               -
hello-group     hello.kafka     2          3               3               0               -               -               -
hello-group     hello.kafka     1          2               2               0               -               -               -
hello-group     hello.kafka     0          4               4               0               -               -               -
yeomko22 commented 3 years ago

kafka-verifiable-producer, consumer

$  bin/kafka-verifiable-producer.sh --bootstrap-server my-kafka:9092 \
> --max-messages 10 \
> --topic verify-test
{"timestamp":1631862276987,"name":"startup_complete"}
[2021-09-17 16:04:37,147] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 1 : {verify-test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
{"timestamp":1631862277283,"name":"producer_send_success","key":null,"value":"0","topic":"verify-test","partition":0,"offset":0}
{"timestamp":1631862277285,"name":"producer_send_success","key":null,"value":"1","topic":"verify-test","partition":0,"offset":1}
{"timestamp":1631862277285,"name":"producer_send_success","key":null,"value":"2","topic":"verify-test","partition":0,"offset":2}
{"timestamp":1631862277286,"name":"producer_send_success","key":null,"value":"3","topic":"verify-test","partition":0,"offset":3}
{"timestamp":1631862277286,"name":"producer_send_success","key":null,"value":"4","topic":"verify-test","partition":0,"offset":4}
{"timestamp":1631862277286,"name":"producer_send_success","key":null,"value":"5","topic":"verify-test","partition":0,"offset":5}
{"timestamp":1631862277286,"name":"producer_send_success","key":null,"value":"6","topic":"verify-test","partition":0,"offset":6}
{"timestamp":1631862277286,"name":"producer_send_success","key":null,"value":"7","topic":"verify-test","partition":0,"offset":7}
{"timestamp":1631862277287,"name":"producer_send_success","key":null,"value":"8","topic":"verify-test","partition":0,"offset":8}
{"timestamp":1631862277287,"name":"producer_send_success","key":null,"value":"9","topic":"verify-test","partition":0,"offset":9}
{"timestamp":1631862277294,"name":"shutdown_complete"}
$ bin/kafka-verifiable-consumer.sh --bootstrap-server my-kafka:9092 \
> --topic verify-test \
> --group-id test-group
{"timestamp":1631862349679,"name":"startup_complete"}
{"timestamp":1631862350018,"name":"partitions_assigned","partitions":[{"topic":"verify-test","partition":0}]}
{"timestamp":1631862350096,"name":"records_consumed","count":10,"partitions":[{"topic":"verify-test","partition":0,"count":10,"minOffset":0,"maxOffset":9}]}
{"timestamp":1631862350108,"name":"offsets_committed","offsets":[{"topic":"verify-test","partition":0,"offset":10}],"success":true}