Jed Rembold
July 23, 2025



We can deploy a Kafka server using Docker Compose
To set up a simple, 1 node kafka server with a web ui:
services:
broker:
image: apache/kafka:latest
hostname: broker
container_name: broker
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_NODE_ID: 1
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@broker:29093
KAFKA_LISTENERS: PLAINTEXT://broker:29092,CONTROLLER://broker:29093,PLAINTEXT_HOST://0.0.0.0:9092
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
kafka-ui:
image: ghcr.io/kafbat/kafka-ui:latest
container_name: kafbat-ui
ports:
- "8091:8080"
environment:
DYNAMIC_CONFIG_ENABLED: 'true'
depends_on:
- brokerkafka-python: Great if working with
stream processing. Very “Pythonic”confluent-kafka: Better for working with
batch processing. More performant based on underlying C libraryconfluent-kafkaconfluent-kafka by default, so you’ll need
to add itConsumer from the
libary (or Producer if you wanted to do
that)from confluent_kafka import Consumer
config = {
'bootstrap.servers': 'localhost',
'group.id': |||your group|||,
'auto.offset.reset': 'earliest'
}
con = Consumer(config)
con.subscribe(['testing'])
try:
more_messages = True
while more_messages:
msg = con.poll(timeout=1.0)
if msg is None:
more_messages = False
else:
print(msg.value().decode())
finally:
con.close()