Introduction
Events
{
"key": "Daniel",
"value": "Logged into their account",
"timestamp": "01-02-2025 8:52:32 AM GMT-03:00"
}Brokers
Topics and Partitions
Partition Redundancy
Producers and Consumers
Hands-on time!
docker-compose.yml
version: '3.5'
services:
broker:
image: apache/kafka:3.9.0
container_name: broker
environment:
KAFKA_NODE_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT_HOST_INTERNAL:PLAINTEXT,PLAINTEXT_HOST_EXTERNAL:PLAINTEXT'
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT_HOST_INTERNAL://broker:9093,PLAINTEXT_HOST_EXTERNAL://localhost:9092'
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@broker:29093'
KAFKA_LISTENERS: 'CONTROLLER://:29093,PLAINTEXT_HOST_INTERNAL://:9093,PLAINTEXT_HOST_EXTERNAL://:9092'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT_HOST_INTERNAL'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_NUM_PARTITIONS: 9
ports:
- "9092:9092"
kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- "8080:8080"
environment:
DYNAMIC_CONFIG_ENABLED: 'true'Represents the ID of this node within the cluster. KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
A comma-separated list of items. Each item is a key-value pair where the key is the listener name and the value is the communication protocol. We're using PLAINTEXT as the protocol, but in real-world scenarios it is recommended to use a protocol like SSL to encrypt data in transit. We declare 3 listeners: PLAINTEXT_HOST_INTERNAL, visible internally within the Docker network; PLAINTEXT_HOST_EXTERNAL, visible on the host machine's network since we're exposing port 9092; and finally CONTROLLER, the controller listener which must be declared separately. KAFKA_ADVERTISED_LISTENERS
The listeners advertised by cluster nodes to help clients locate other nodes. KAFKA_PROCESS_ROLES
Dictates the roles of this cluster node. In this case, since we're using KRaft mode, this node acts as both a controller and a broker. KAFKA_CONTROLLER_QUORUM_VOTERS
Indicates the other voting nodes in situations where consensus is required, such as when electing a new partition leader. Since we're creating a single-node cluster, only this node is listed. KAFKA_LISTENERS
All listeners declared by this cluster node. KAFKA_INTER_BROKER_LISTENER_NAME
The name of the listener used for communication between brokers in the cluster, for tasks such as topic replication. KAFKA_CONTROLLER_LISTENER_NAMES
The names of the listeners used for controller communication. KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
The replication factor of a special Kafka topic that stores the offsets of each consumer. It can take a maximum value equal to the number of broker nodes in the cluster. Since we're using only one, its value must be 1. KAFKA_NUM_PARTITIONS
When a topic is automatically created by a consumer, Kafka uses this setting to determine the default number of partitions to use.








