DrMaemi / blog

1 stars 0 forks source link

[Kafka] Getting Started #186

Open DrMaemi opened 2 months ago

DrMaemi commented 2 months ago

MacOS

  1. https://www.apache.org/dyn/closer.cgi?path=/kafka/3.7.0/kafka_2.13-3.7.0.tgz 다운받아 압축 해제
    $ tar -xzf kafka_2.13-3.7.0.tgz
    $ cd kafka_2.13-3.7.0
  2. ZK 실행 (사전에 설치)
    bin/zkServer.sh start
  3. Kafka 실행
    bin/kafka-server-start.sh config/server.properties
  4. Topic 생성 등 동작 수행
    bin/kafka-topics.sh --create --partitions 1 --replication-factor 1 --topic quickstart-events --bootstrap-server localhost:9092
  5. Topic 에 event publish 해보기
    $ bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
    >This is my first event
    [2024-04-09 00:57:37,685] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 6 : {quickstart-events=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
    >Is there ?
    >This is my second event
    >This is realtime event publishing
  6. Event read 해보기
    $ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
    This is my first event
    Is there ?
    This is my second event
    This is realtime event publishing
  7. Topic describe
    bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
    Topic: quickstart-events    TopicId: j9jxzPlMQUiIcgY4vuLA_w PartitionCount: 1   ReplicationFactor: 1    Configs:
    Topic: quickstart-events    Partition: 0    Leader: 0   Replicas: 0 Isr: 0
  8. Consumer group describe
    
    bin/kafka-consumer-groups.sh --all-groups --bootstrap-server localhost:9092 --describe

GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID console-consumer-80282 quickstart-events 0 - 4 - console-consumer-e1a1fbfc-acca-4b72-aee2-cea8219d4e54 /192.168.219.102 console-consumer



### Java Kafka Stream Application
- [WordCountDemo.java, *github.com/apache/kafka*](https://github.com/apache/kafka/blob/3.6/streams/examples/src/main/java/org/apache/kafka/streams/examples/wordcount/WordCountDemo.java)
- ["TUTORIAL: WRITE A KAFKA STREAMS APPLICATION," *kafka.apache.org*](https://kafka.apache.org/37/documentation/streams/tutorial)

## A. 참조
- [https://kafka.apache.org/quickstart](https://kafka.apache.org/quickstart)
- [https://kafka.apache.org/documentation/#operations](https://kafka.apache.org/documentation/#operations)