Skip to content

Commit

Permalink
Add scripts to start kafka locally and to subscribe to local kafka topic
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Sep 15, 2023
1 parent b5a2b5c commit dca1d68
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3"

services:
kafka:
image: bitnami/kafka:3.5.0
container_name: bitnami_kafka
ports:
- "9092:9092"
environment:
KAFKA_ENABLE_KRAFT: "true"
KAFKA_CFG_NODE_ID: "1"
KAFKA_CFG_PROCESS_ROLES: "broker,controller"
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093"
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://127.0.0.1:9092"
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_BROKER_ID: "1"
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "1@kafka:9093"
ALLOW_PLAINTEXT_LISTENER: "true"
healthcheck:
test: ["CMD-SHELL", "kafka-topics.sh --bootstrap-server kafka:9092 --list"]
start_period: 10s
interval: 5s
timeout: 10s
retries: 5
3 changes: 3 additions & 0 deletions scripts/start_kafka_broker_locally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker-compose -f ./scripts/services.yml up -d --no-recreate
3 changes: 3 additions & 0 deletions scripts/stop_kafka_broker_locally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker-compose -f ./scripts/services.yml down
10 changes: 10 additions & 0 deletions scripts/subscribe_to_kafka_broker_locally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo "Usage: $0 <topic>"
exit 1
fi

topic="$1"

docker exec -it bitnami_kafka /opt/bitnami/kafka/bin/kafka-console-consumer.sh --consumer.config /opt/bitnami/kafka/config/consumer.properties --bootstrap-server kafka:9092 --topic "$topic"

0 comments on commit dca1d68

Please sign in to comment.