Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added container ID fetch script #52

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading