1#!/usr/bin/env bash 2# Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16 17set -e 18set -o pipefail 19 20if [ "$#" -ne 2 ]; then 21 echo "Usage: $0 start|stop <kafka container name>" >&2 22 exit 1 23fi 24 25action=$1 26container=$2 27if [ "$action" == "start" ]; then 28 echo pull spotify/kafka 29 docker pull spotify/kafka 30 echo pull spotify/kafka successfully 31 docker run -d --rm --net=host --name=$container spotify/kafka 32 echo Wait 5 secs until kafka is up and running 33 sleep 5 34 echo Create test topic 35 docker exec $container bash -c '/opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test' 36 echo Create test message 37 docker exec $container bash -c 'echo -e "D0\nD1\nD2\nD3\nD4\nD5\nD6\nD7\nD8\nD9" > /test' 38 echo Produce test message 39 docker exec $container bash -c '/opt/kafka_2.11-0.10.1.0/bin/kafka-console-producer.sh --topic test --broker-list 127.0.0.1:9092 < /test' 40 echo Container $container started successfully 41elif [ "$action" == "stop" ]; then 42 docker rm -f $container 43 echo Container $container removed successfully 44else 45 echo "Usage: $0 start|stop <kafka container name>" >&2 46 exit 1 47fi 48 49 50 51