Skip to content

Latest commit

 

History

History
108 lines (79 loc) · 3.18 KB

File metadata and controls

108 lines (79 loc) · 3.18 KB

Kafka

For working with Apache Samaz.

I have no name!@da987e387810:/opt/bitnami/kafka$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic wikipedia-raw --from-beginning

I have no name!@da987e387810:/opt/bitnami/kafka$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic wikipedia-stats --from-beginning
  • 3.7.0
$ vi /etc/kafka/docker/launch
...
exec /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
# Terminal 1
$ docker exec -it kafka-broker bash 
1740adfd05ab:/$ cd /opt/kafka/
1740adfd05ab:/opt/kafka$ bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
Created topic quickstart-events.
1740adfd05ab:/opt/kafka$ bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
Topic: quickstart-events        TopicId: _Y_ebTzURTuk0wTOL_QBdQ PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: quickstart-events        Partition: 0    Leader: 1       Replicas: 1     Isr: 1
1740adfd05ab:/opt/kafka$ bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
>This is my first event
>This is my second event

# Terminal 2
$ docker exec -it kafka-broker bash
1740adfd05ab:/$ cd /opt/kafka/
1740adfd05ab:/opt/kafka$ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
This is my first event

This is my first event
This is my second event

kafka-ui

# server.properties
# DEPLOY_ENV
advertised.listeners=PLAINTEXT://kafka-broker:9092

Access http://localhost:18080/

Kafka Cluser

  • Cluster name: kafka-broker
  • Bootstrap servers: kafka-broker, 9092; 192.168.3.182, 9094 with out container access.

Clients

Out Container Access

Add EXTERNAL

# server.properties
listeners=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
advertised.listeners=PLAINTEXT://127.0.0.1:9092,EXTERNAL://192.168.3.182:9094

Python

# Windows WSL
$ python --version
Python 3.11.5
$ python -m virtualenv .venv
$ source .venv/Scripts/activate
$ pip install kafka-python
$ pip freeze > requirements.txt

# make user topic 'quickstart-events' exist

$ python producer.py
$ python consumer.py

Java/Scala

# Terminal 1
$ amm --watch producer.sc

# Terminal 2
$ amm --watch consumer.sc