0
0
Kafkadevops~5 mins

Broker nodes in Kafka - Commands & Configuration

Choose your learning style9 modes available
Introduction
Kafka broker nodes are servers that store and manage messages in Kafka. They help distribute data and handle requests from producers and consumers, making sure messages are saved and delivered reliably.
When you want to run a Kafka server that stores and manages message data.
When you need to add more capacity to handle more messages or users by adding more brokers.
When you want to ensure your messaging system keeps working even if one server fails.
When you want to balance the load of message traffic across multiple servers.
When you want to configure Kafka to listen on specific network addresses and ports.
Config File - server.properties
server.properties
broker.id=1
listeners=PLAINTEXT://0.0.0.0:9092
log.dirs=/tmp/kafka-logs
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=localhost:2181

broker.id: Unique ID for this broker node.

listeners: Network address and port where Kafka listens for connections.

log.dirs: Directory where Kafka stores message logs.

num.network.threads and num.io.threads: Threads for handling network and disk I/O.

socket.*: Network buffer sizes and max request size.

log.retention.*: How long and how big logs are kept.

zookeeper.connect: Address of ZooKeeper managing Kafka cluster metadata.

Commands
Starts the Kafka broker node using the configuration in server.properties. This launches the server to accept connections and manage messages.
Terminal
kafka-server-start.sh server.properties
Expected OutputExpected
[2024-06-01 12:00:00,000] INFO Kafka version : 3.5.0 (org.apache.kafka.common.utils.AppInfoParser) [2024-06-01 12:00:00,001] INFO Kafka startTimeMs : 1685611200000 (org.apache.kafka.common.utils.AppInfoParser) [2024-06-01 12:00:01,500] INFO [KafkaServer id=1] started (kafka.server.KafkaServer)
Lists all topics managed by the Kafka broker to verify the broker is running and accessible.
Terminal
kafka-topics.sh --bootstrap-server localhost:9092 --list
Expected OutputExpected
example-topic my-topic
--bootstrap-server - Specifies the Kafka broker address to connect to.
Shows the API versions supported by the broker, confirming the broker is active and communicating.
Terminal
kafka-broker-api-versions.sh --bootstrap-server localhost:9092
Expected OutputExpected
Broker: 1 (id: 1 rack: null) ApiVersions: Produce (0-9) Fetch (0-11) ListOffsets (0-4) Metadata (0-8) ...
--bootstrap-server - Specifies the Kafka broker address to connect to.
Key Concept

If you remember nothing else from this pattern, remember: each Kafka broker node stores and manages messages and must have a unique broker.id and proper network settings to work correctly.

Common Mistakes
Using the same broker.id on multiple Kafka broker nodes.
Kafka requires unique broker IDs to identify each node; duplicates cause conflicts and cluster errors.
Assign a unique broker.id number to each Kafka broker node in its server.properties file.
Not setting the listeners property correctly, causing the broker to be unreachable.
If listeners is not set or set incorrectly, clients cannot connect to the broker.
Set listeners to the correct IP address and port, e.g., PLAINTEXT://0.0.0.0:9092 to listen on all interfaces.
Summary
Create a server.properties file to configure each Kafka broker node with unique ID and network settings.
Start the Kafka broker using kafka-server-start.sh with the configuration file.
Verify the broker is running by listing topics and checking API versions.