Skip to content

Commit

Permalink
Merge pull request #52 from OpenNyAI/container-id
Browse files Browse the repository at this point in the history
Added container ID fetch script
  • Loading branch information
sameersegal authored May 22, 2024
2 parents c323bc0 + 87c8d3b commit 537487e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
10 changes: 9 additions & 1 deletion scripts/create-topic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

topic=$1

docker exec -i jb-manager-kafka-1 kafka-topics.sh --create --bootstrap-server localhost:9092 --topic $topic
# Get the container ID for the service
CONTAINER_ID=$(./scripts/get-container-id.sh kafka)

# Check for error
if [ $? -ne 0 ]; then
exit 1
fi

# Create the topic
docker exec -i $CONTAINER_ID kafka-topics.sh --create --bootstrap-server localhost:9092 --topic $topic



Expand Down
10 changes: 9 additions & 1 deletion scripts/delete-topic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

topic=$1

docker exec -i jb-manager-kafka-1 kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic $topic
# Get the container ID for the service
CONTAINER_ID=$(./scripts/get-container-id.sh kafka)

# Check for error
if [ $? -ne 0 ]; then
exit 1
fi

docker exec -i $CONTAINER_ID kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic $topic



Expand Down
12 changes: 12 additions & 0 deletions scripts/get-container-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Service name as defined in docker-compose.yml
SERVICE_NAME=$1

# Get the container ID for the service
CONTAINER_ID=$(docker-compose ps -q $SERVICE_NAME)

# Check if the container is running
if [ -z "$CONTAINER_ID" ]; then
echo "No running container found for service: $SERVICE_NAME"
exit 1
fi
echo $CONTAINER_ID
10 changes: 9 additions & 1 deletion scripts/read-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
topic=$1
message=$2

docker exec -i jb-manager-kafka-1 kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic $topic
# Get the container ID for the service
CONTAINER_ID=$(./scripts/get-container-id.sh kafka)

# Check for error
if [ $? -ne 0 ]; then
exit 1
fi

docker exec -i $CONTAINER_ID kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic $topic
10 changes: 9 additions & 1 deletion scripts/send-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
topic=$1
message=$2

echo $message | docker exec -i jb-manager-kafka-1 kafka-console-producer.sh --bootstrap-server localhost:9092 --topic $topic
# Get the container ID for the service
CONTAINER_ID=$(./scripts/get-container-id.sh kafka)

# Check for error
if [ $? -ne 0 ]; then
exit 1
fi

echo $message | docker exec -i $CONTAINER_ID kafka-console-producer.sh --bootstrap-server localhost:9092 --topic $topic
echo "Sent message to $topic"

0 comments on commit 537487e

Please sign in to comment.