├── .gitignore ├── .travis.yml ├── zk-single-kafka-single.yml ├── zk-multiple-kafka-single.yml ├── test.sh ├── zk-single-kafka-multiple.yml ├── zk-multiple-kafka-multiple.yml ├── full-stack.yml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | zk-single-kafka-single/* 2 | zk-single-kafka-multiple/* 3 | zk-multiple-kafka-single/* 4 | zk-multiple-kafka-multiple/* 5 | full-stack/* 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # this file is only used for GitHub 2 | # it is not related to your Kafka Streams learning 3 | sudo: required 4 | 5 | env: 6 | - DOCKER_HOST_IP=127.0.0.1 7 | # - DOCKER_HOST_IP=192.168.99.100 8 | 9 | services: 10 | - docker 11 | 12 | addons: 13 | # install the kafka binaries 14 | apt: 15 | sources: 16 | - sourceline: 'deb [arch=amd64] https://packages.confluent.io/deb/4.1 stable main' 17 | key_url: 'https://packages.confluent.io/deb/4.1/archive.key' 18 | packages: 19 | - confluent-platform-oss-2.11 20 | # - kafkacat 21 | 22 | script: 23 | # test the java components 24 | - ./test.sh zk-single-kafka-single.yml 2 25 | - ./test.sh zk-multiple-kafka-single.yml 4 26 | - ./test.sh zk-single-kafka-multiple.yml 4 27 | - ./test.sh zk-multiple-kafka-multiple.yml 6 28 | - ./test.sh full-stack.yml 10 29 | -------------------------------------------------------------------------------- /zk-single-kafka-single.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | zoo1: 5 | image: zookeeper:3.4.9 6 | hostname: zoo1 7 | ports: 8 | - "2181:2181" 9 | environment: 10 | ZOO_MY_ID: 1 11 | ZOO_PORT: 2181 12 | ZOO_SERVERS: server.1=zoo1:2888:3888 13 | volumes: 14 | - ./zk-single-kafka-single/zoo1/data:/data 15 | - ./zk-single-kafka-single/zoo1/datalog:/datalog 16 | 17 | kafka1: 18 | image: confluentinc/cp-kafka:5.5.1 19 | hostname: kafka1 20 | ports: 21 | - "9092:9092" 22 | environment: 23 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092 24 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 25 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 26 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" 27 | KAFKA_BROKER_ID: 1 28 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 29 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 30 | volumes: 31 | - ./zk-single-kafka-single/kafka1/data:/var/lib/kafka/data 32 | depends_on: 33 | - zoo1 34 | -------------------------------------------------------------------------------- /zk-multiple-kafka-single.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | zoo1: 5 | image: zookeeper:3.4.9 6 | hostname: zoo1 7 | ports: 8 | - "2181:2181" 9 | environment: 10 | ZOO_MY_ID: 1 11 | ZOO_PORT: 2181 12 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 13 | volumes: 14 | - ./zk-multiple-kafka-single/zoo1/data:/data 15 | - ./zk-multiple-kafka-single/zoo1/datalog:/datalog 16 | 17 | zoo2: 18 | image: zookeeper:3.4.9 19 | hostname: zoo2 20 | ports: 21 | - "2182:2182" 22 | environment: 23 | ZOO_MY_ID: 2 24 | ZOO_PORT: 2182 25 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 26 | volumes: 27 | - ./zk-multiple-kafka-single/zoo2/data:/data 28 | - ./zk-multiple-kafka-single/zoo2/datalog:/datalog 29 | 30 | zoo3: 31 | image: zookeeper:3.4.9 32 | hostname: zoo3 33 | ports: 34 | - "2183:2183" 35 | environment: 36 | ZOO_MY_ID: 3 37 | ZOO_PORT: 2183 38 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 39 | volumes: 40 | - ./zk-multiple-kafka-single/zoo3/data:/data 41 | - ./zk-multiple-kafka-single/zoo3/datalog:/datalog 42 | 43 | 44 | kafka1: 45 | image: confluentinc/cp-kafka:5.5.1 46 | hostname: kafka1 47 | ports: 48 | - "9092:9092" 49 | environment: 50 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092 51 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 52 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 53 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183" 54 | KAFKA_BROKER_ID: 1 55 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 56 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 57 | volumes: 58 | - ./zk-multiple-kafka-single/kafka1/data:/var/lib/kafka/data 59 | depends_on: 60 | - zoo1 61 | - zoo2 62 | - zoo3 63 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | export file=$1 5 | #!/bin/bash 6 | f () { 7 | errcode=$? # save the exit code as the first thing done in the trap function 8 | echo "error $errorcode" 9 | echo "the command executing at the time of the error was" 10 | echo "$BASH_COMMAND" 11 | echo "on line ${BASH_LINENO[0]}" 12 | # do some error handling, cleanup, logging, notification 13 | # $BASH_COMMAND contains the command that was being executed at the time of the trap 14 | # ${BASH_LINENO[0]} contains the line number in the script of that command 15 | # exit the script or return to try again, etc. 16 | # creating stack... 17 | docker-compose -f $file down 18 | exit $errcode # or use some other value or do return instead 19 | } 20 | trap f ERR 21 | 22 | all_great(){ 23 | # for testing 24 | echo "Verifying Process" 25 | running=`docker-compose -f $1 ps | grep Up | wc -l` 26 | if [ "$running" != "$2" ]; then 27 | # for logging 28 | docker-compose -f $1 ps 29 | # debug 30 | docker-compose -f $1 logs 31 | exit 1 32 | fi 33 | } 34 | 35 | kafka_tests(){ 36 | echo "Testing Kafka" 37 | topic="testtopic" 38 | if grep -q kafka3 $1; then replication_factor="3"; else replication_factor="1"; fi 39 | for i in 1 2 3 4 5; do echo "trying to create test topic" && kafka-topics --create --topic $topic --replication-factor $replication_factor --partitions 12 --zookeeper $DOCKER_HOST_IP:2181 && break || sleep 5; done 40 | for x in {1..100}; do echo $x; done | kafka-console-producer --broker-list $DOCKER_HOST_IP:9092 --topic $topic 41 | rows=`kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic $topic --from-beginning --timeout-ms 2000 | wc -l` 42 | # rows=`kafkacat -C -b $DOCKER_HOST_IP:9092 -t $topic -o beginning -e | wc -l ` 43 | if [ "$rows" != "100" ]; then 44 | kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic test-topic --from-beginning --timeout-ms 2000 | wc -l 45 | exit 1 46 | else 47 | echo "Kafka Test Success" 48 | fi 49 | } 50 | 51 | # creating stack... 52 | docker-compose -f $file up -d 53 | sleep 10 54 | # logging 55 | docker-compose -f $file ps 56 | # tests 57 | all_great $1 $2 58 | kafka_tests $1 59 | all_great $1 $2 60 | # teardown 61 | docker-compose -f $file down 62 | echo "Success!" -------------------------------------------------------------------------------- /zk-single-kafka-multiple.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | zoo1: 5 | image: zookeeper:3.4.9 6 | hostname: zoo1 7 | ports: 8 | - "2181:2181" 9 | environment: 10 | ZOO_MY_ID: 1 11 | ZOO_PORT: 2181 12 | ZOO_SERVERS: server.1=zoo1:2888:3888 13 | volumes: 14 | - ./zk-single-kafka-multiple/zoo1/data:/data 15 | - ./zk-single-kafka-multiple/zoo1/datalog:/datalog 16 | 17 | kafka1: 18 | image: confluentinc/cp-kafka:5.5.1 19 | hostname: kafka1 20 | ports: 21 | - "9092:9092" 22 | environment: 23 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092 24 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 25 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 26 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" 27 | KAFKA_BROKER_ID: 1 28 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 29 | volumes: 30 | - ./zk-single-kafka-multiple/kafka1/data:/var/lib/kafka/data 31 | depends_on: 32 | - zoo1 33 | 34 | kafka2: 35 | image: confluentinc/cp-kafka:5.5.1 36 | hostname: kafka2 37 | ports: 38 | - "9093:9093" 39 | environment: 40 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19093,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093 41 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 42 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 43 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" 44 | KAFKA_BROKER_ID: 2 45 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 46 | volumes: 47 | - ./zk-single-kafka-multiple/kafka2/data:/var/lib/kafka/data 48 | depends_on: 49 | - zoo1 50 | 51 | 52 | kafka3: 53 | image: confluentinc/cp-kafka:5.5.1 54 | hostname: kafka3 55 | ports: 56 | - "9094:9094" 57 | environment: 58 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka3:19094,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9094 59 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 60 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 61 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" 62 | KAFKA_BROKER_ID: 3 63 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 64 | volumes: 65 | - ./zk-single-kafka-multiple/kafka3/data:/var/lib/kafka/data 66 | depends_on: 67 | - zoo1 68 | -------------------------------------------------------------------------------- /zk-multiple-kafka-multiple.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | zoo1: 5 | image: zookeeper:3.4.9 6 | hostname: zoo1 7 | ports: 8 | - "2181:2181" 9 | environment: 10 | ZOO_MY_ID: 1 11 | ZOO_PORT: 2181 12 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 13 | volumes: 14 | - ./zk-multiple-kafka-multiple/zoo1/data:/data 15 | - ./zk-multiple-kafka-multiple/zoo1/datalog:/datalog 16 | 17 | zoo2: 18 | image: zookeeper:3.4.9 19 | hostname: zoo2 20 | ports: 21 | - "2182:2182" 22 | environment: 23 | ZOO_MY_ID: 2 24 | ZOO_PORT: 2182 25 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 26 | volumes: 27 | - ./zk-multiple-kafka-multiple/zoo2/data:/data 28 | - ./zk-multiple-kafka-multiple/zoo2/datalog:/datalog 29 | 30 | zoo3: 31 | image: zookeeper:3.4.9 32 | hostname: zoo3 33 | ports: 34 | - "2183:2183" 35 | environment: 36 | ZOO_MY_ID: 3 37 | ZOO_PORT: 2183 38 | ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 39 | volumes: 40 | - ./zk-multiple-kafka-multiple/zoo3/data:/data 41 | - ./zk-multiple-kafka-multiple/zoo3/datalog:/datalog 42 | 43 | 44 | kafka1: 45 | image: confluentinc/cp-kafka:5.5.1 46 | hostname: kafka1 47 | ports: 48 | - "9092:9092" 49 | environment: 50 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092 51 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 52 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 53 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183" 54 | KAFKA_BROKER_ID: 1 55 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 56 | volumes: 57 | - ./zk-multiple-kafka-multiple/kafka1/data:/var/lib/kafka/data 58 | depends_on: 59 | - zoo1 60 | - zoo2 61 | - zoo3 62 | 63 | kafka2: 64 | image: confluentinc/cp-kafka:5.5.1 65 | hostname: kafka2 66 | ports: 67 | - "9093:9093" 68 | environment: 69 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19093,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093 70 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 71 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 72 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183" 73 | KAFKA_BROKER_ID: 2 74 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 75 | volumes: 76 | - ./zk-multiple-kafka-multiple/kafka2/data:/var/lib/kafka/data 77 | depends_on: 78 | - zoo1 79 | - zoo2 80 | - zoo3 81 | 82 | kafka3: 83 | image: confluentinc/cp-kafka:5.5.1 84 | hostname: kafka3 85 | ports: 86 | - "9094:9094" 87 | environment: 88 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka3:19094,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9094 89 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 90 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 91 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183" 92 | KAFKA_BROKER_ID: 3 93 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 94 | volumes: 95 | - ./zk-multiple-kafka-multiple/kafka3/data:/var/lib/kafka/data 96 | depends_on: 97 | - zoo1 98 | - zoo2 99 | - zoo3 100 | -------------------------------------------------------------------------------- /full-stack.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | zoo1: 5 | image: zookeeper:3.4.9 6 | restart: unless-stopped 7 | hostname: zoo1 8 | ports: 9 | - "2181:2181" 10 | environment: 11 | ZOO_MY_ID: 1 12 | ZOO_PORT: 2181 13 | ZOO_SERVERS: server.1=zoo1:2888:3888 14 | volumes: 15 | - ./full-stack/zoo1/data:/data 16 | - ./full-stack/zoo1/datalog:/datalog 17 | 18 | 19 | kafka1: 20 | image: confluentinc/cp-kafka:5.5.1 21 | hostname: kafka1 22 | ports: 23 | - "9092:9092" 24 | environment: 25 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092 26 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 27 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 28 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" 29 | KAFKA_BROKER_ID: 1 30 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 31 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 32 | volumes: 33 | - ./full-stack/kafka1/data:/var/lib/kafka/data 34 | depends_on: 35 | - zoo1 36 | 37 | kafka-schema-registry: 38 | image: confluentinc/cp-schema-registry:5.5.1 39 | hostname: kafka-schema-registry 40 | ports: 41 | - "8081:8081" 42 | environment: 43 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka1:19092 44 | SCHEMA_REGISTRY_HOST_NAME: kafka-schema-registry 45 | SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081 46 | depends_on: 47 | - zoo1 48 | - kafka1 49 | 50 | schema-registry-ui: 51 | image: landoop/schema-registry-ui:0.9.5 52 | hostname: kafka-schema-registry-ui 53 | ports: 54 | - "8001:8000" 55 | environment: 56 | SCHEMAREGISTRY_URL: http://kafka-schema-registry:8081/ 57 | PROXY: "true" 58 | depends_on: 59 | - kafka-schema-registry 60 | 61 | kafka-rest-proxy: 62 | image: confluentinc/cp-kafka-rest:5.5.1 63 | hostname: kafka-rest-proxy 64 | ports: 65 | - "8082:8082" 66 | environment: 67 | # KAFKA_REST_ZOOKEEPER_CONNECT: zoo1:2181 68 | KAFKA_REST_LISTENERS: http://0.0.0.0:8082/ 69 | KAFKA_REST_SCHEMA_REGISTRY_URL: http://kafka-schema-registry:8081/ 70 | KAFKA_REST_HOST_NAME: kafka-rest-proxy 71 | KAFKA_REST_BOOTSTRAP_SERVERS: PLAINTEXT://kafka1:19092 72 | depends_on: 73 | - zoo1 74 | - kafka1 75 | - kafka-schema-registry 76 | 77 | kafka-topics-ui: 78 | image: landoop/kafka-topics-ui:0.9.4 79 | hostname: kafka-topics-ui 80 | ports: 81 | - "8000:8000" 82 | environment: 83 | KAFKA_REST_PROXY_URL: "http://kafka-rest-proxy:8082/" 84 | PROXY: "true" 85 | depends_on: 86 | - zoo1 87 | - kafka1 88 | - kafka-schema-registry 89 | - kafka-rest-proxy 90 | 91 | kafka-connect: 92 | image: confluentinc/cp-kafka-connect:5.5.1 93 | hostname: kafka-connect 94 | ports: 95 | - "8083:8083" 96 | environment: 97 | CONNECT_BOOTSTRAP_SERVERS: "kafka1:19092" 98 | CONNECT_REST_PORT: 8083 99 | CONNECT_GROUP_ID: compose-connect-group 100 | CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs 101 | CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets 102 | CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status 103 | CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter 104 | CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: 'http://kafka-schema-registry:8081' 105 | CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter 106 | CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: 'http://kafka-schema-registry:8081' 107 | CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter" 108 | CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter" 109 | CONNECT_REST_ADVERTISED_HOST_NAME: "kafka-connect" 110 | CONNECT_LOG4J_ROOT_LOGLEVEL: "INFO" 111 | CONNECT_LOG4J_LOGGERS: "org.apache.kafka.connect.runtime.rest=WARN,org.reflections=ERROR" 112 | CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: "1" 113 | CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: "1" 114 | CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: "1" 115 | CONNECT_PLUGIN_PATH: '/usr/share/java,/etc/kafka-connect/jars' 116 | volumes: 117 | - ./connectors:/etc/kafka-connect/jars/ 118 | depends_on: 119 | - zoo1 120 | - kafka1 121 | - kafka-schema-registry 122 | - kafka-rest-proxy 123 | 124 | kafka-connect-ui: 125 | image: landoop/kafka-connect-ui:0.9.7 126 | hostname: kafka-connect-ui 127 | ports: 128 | - "8003:8000" 129 | environment: 130 | CONNECT_URL: "http://kafka-connect:8083/" 131 | PROXY: "true" 132 | depends_on: 133 | - kafka-connect 134 | 135 | ksqldb-server: 136 | image: confluentinc/cp-ksqldb-server:5.5.1 137 | hostname: ksqldb-server 138 | ports: 139 | - "8088:8088" 140 | environment: 141 | KSQL_BOOTSTRAP_SERVERS: PLAINTEXT://kafka1:19092 142 | KSQL_LISTENERS: http://0.0.0.0:8088/ 143 | KSQL_KSQL_SERVICE_ID: ksqldb-server_ 144 | depends_on: 145 | - zoo1 146 | - kafka1 147 | 148 | zoonavigator: 149 | image: elkozmon/zoonavigator:0.8.0 150 | ports: 151 | - "8004:8000" 152 | environment: 153 | HTTP_PORT: 8000 154 | AUTO_CONNECT_CONNECTION_STRING: zoo1:2181 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/simplesteph/kafka-stack-docker-compose.svg?branch=master)](https://travis-ci.org/simplesteph/kafka-stack-docker-compose) 2 | 3 | # kafka-stack-docker-compose 4 | 5 | This replicates as well as possible real deployment configurations, where you have your zookeeper servers and kafka servers actually all distinct from each other. This solves all the networking hurdles that comes with Docker and docker-compose, and is compatible cross platform. 6 | 7 | **UPDATE**: No /etc/hosts file changes are necessary anymore. Explanations at: https://rmoff.net/2018/08/02/kafka-listeners-explained/ 8 | 9 | ## Stack version 10 | 11 | - Zookeeper version: 3.4.9 12 | - Kafka version: 2.5.0 (Confluent 5.5.1) 13 | - Kafka Schema Registry: Confluent 5.5.1 14 | - Kafka Schema Registry UI: 0.9.5 15 | - Kafka Rest Proxy: Confluent 5.5.1 16 | - Kafka Topics UI: 0.9.4 17 | - Kafka Connect: Confluent 5.5.1 18 | - Kafka Connect UI: 0.9.7 19 | - ksqlDB Server: Confluent 5.5.1 20 | - Zoonavigator: 0.8.0 21 | 22 | 23 | ## Optional: Kafka Desktop Application 24 | 25 | Once you have started your cluster, you can use [Conduktor](https://www.conduktor.io/) to easily manage it. 26 | Just connect against `localhost:9092` if using Docker, or `192.168.99.100` if using Docker Toolbox 27 | 28 | # Requirements 29 | 30 | ## Docker 31 | 32 | Please export your environment before starting the stack: 33 | ``` 34 | export DOCKER_HOST_IP=127.0.0.1 35 | ``` 36 | (that's the default value and you actually don't need to do a thing) 37 | 38 | ## Docker-Toolbox 39 | If you are using Docker for Mac <= 1.11, or Docker Toolbox for Windows 40 | (your docker machine IP is usually `192.168.99.100`) 41 | 42 | Please export your environment before starting the stack: 43 | ``` 44 | export DOCKER_HOST_IP=192.168.99.100 45 | ``` 46 | 47 | ## Single Zookeeper / Single Kafka 48 | 49 | This configuration fits most development requirements. 50 | 51 | - Zookeeper will be available at `$DOCKER_HOST_IP:2181` 52 | - Kafka will be available at `$DOCKER_HOST_IP:9092` 53 | 54 | 55 | Run with: 56 | ``` 57 | docker-compose -f zk-single-kafka-single.yml up 58 | docker-compose -f zk-single-kafka-single.yml down 59 | ``` 60 | 61 | ## Single Zookeeper / Multiple Kafka 62 | 63 | If you want to have three brokers and experiment with kafka replication / fault-tolerance. 64 | 65 | - Zookeeper will be available at `$DOCKER_HOST_IP:2181` 66 | - Kafka will be available at `$DOCKER_HOST_IP:9092,$DOCKER_HOST_IP:9093,$DOCKER_HOST_IP:9094` 67 | 68 | 69 | Run with: 70 | ``` 71 | docker-compose -f zk-single-kafka-multiple.yml up 72 | docker-compose -f zk-single-kafka-multiple.yml down 73 | ``` 74 | 75 | ## Multiple Zookeeper / Single Kafka 76 | 77 | If you want to have three zookeeper nodes and experiment with zookeeper fault-tolerance. 78 | 79 | - Zookeeper will be available at `$DOCKER_HOST_IP:2181,$DOCKER_HOST_IP:2182,$DOCKER_HOST_IP:2183` 80 | - Kafka will be available at `$DOCKER_HOST_IP:9092` 81 | 82 | Run with: 83 | ``` 84 | docker-compose -f zk-multiple-kafka-single.yml up 85 | docker-compose -f zk-multiple-kafka-single.yml down 86 | ``` 87 | 88 | 89 | ## Multiple Zookeeper / Multiple Kafka 90 | 91 | If you want to have three zookeeper nodes and three kafka brokers to experiment with production setup. 92 | 93 | - Zookeeper will be available at `$DOCKER_HOST_IP:2181,$DOCKER_HOST_IP:2182,$DOCKER_HOST_IP:2183` 94 | - Kafka will be available at `$DOCKER_HOST_IP:9092,$DOCKER_HOST_IP:9093,$DOCKER_HOST_IP:9094` 95 | 96 | Run with: 97 | ``` 98 | docker-compose -f zk-multiple-kafka-multiple.yml up 99 | docker-compose -f zk-multiple-kafka-multiple.yml down 100 | ``` 101 | 102 | 103 | ## Full stack 104 | 105 | - Single Zookeeper: `$DOCKER_HOST_IP:2181` 106 | - Single Kafka: `$DOCKER_HOST_IP:9092` 107 | - Kafka Schema Registry: `$DOCKER_HOST_IP:8081` 108 | - Kafka Schema Registry UI: `$DOCKER_HOST_IP:8001` 109 | - Kafka Rest Proxy: `$DOCKER_HOST_IP:8082` 110 | - Kafka Topics UI: `$DOCKER_HOST_IP:8000` 111 | - Kafka Connect: `$DOCKER_HOST_IP:8083` 112 | - Kafka Connect UI: `$DOCKER_HOST_IP:8003` 113 | - KSQL Server: `$DOCKER_HOST_IP:8088` 114 | - Zoonavigator Web: `$DOCKER_HOST_IP:8004` 115 | 116 | 117 | Run with: 118 | ``` 119 | docker-compose -f full-stack.yml up 120 | docker-compose -f full-stack.yml down 121 | ``` 122 | 123 | # FAQ 124 | 125 | ## Kafka 126 | 127 | **Q: Kafka's log is too verbose, how can I reduce it?** 128 | 129 | A: Add the following line to your docker-compose environment variables: `KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"`. Full logging control can be accessed here: https://github.com/confluentinc/cp-docker-images/blob/master/debian/kafka/include/etc/confluent/docker/log4j.properties.template 130 | 131 | **Q: How do I delete data to start fresh?** 132 | 133 | A: Your data is persisted from within the docker compose folder, so if you want for example to reset the data in the full-stack docker compose, first do a `docker-compose -f full-stack.yml down`, then remove the directory `full-stack`, for example by doing `rm -r -f full-stack`. 134 | 135 | **Q: Can I change the zookeeper ports?** 136 | 137 | A: yes. Say you want to change `zoo1` port to `12181` (only relevant lines are shown): 138 | ``` 139 | zoo1: 140 | ports: 141 | - "12181:12181" 142 | environment: 143 | ZOO_PORT: 12181 144 | 145 | kafka1: 146 | environment: 147 | KAFKA_ZOOKEEPER_CONNECT: "zoo1:12181" 148 | ``` 149 | 150 | **Q: Can I change the Kafka ports?** 151 | 152 | A: yes. Say you want to change `kafka1` port to `12345` (only relevant lines are shown). Note only `LISTENER_DOCKER_EXTERNAL` changes: 153 | ``` 154 | kafka1: 155 | image: confluentinc/cp-kafka:5.5.1 156 | hostname: kafka1 157 | ports: 158 | - "12345:12345" 159 | environment: 160 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:12345 161 | ``` 162 | 163 | **Q: Kafka is using a lot of disk space for testing. Can I reduce it?** 164 | 165 | A: yes. This is for testing only!!! Reduce the KAFKA_LOG_SEGMENT_BYTES to 16MB and the KAFKA_LOG_RETENTION_BYTES to 128MB 166 | 167 | ``` 168 | kafka1: 169 | image: confluentinc/cp-kafka:5.5.1 170 | ... 171 | environment: 172 | ... 173 | # For testing small segments 16MB and retention of 128MB 174 | KAFKA_LOG_SEGMENT_BYTES: 16777216 175 | KAFKA_LOG_RETENTION_BYTES: 134217728 176 | ``` 177 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Stephane Maarek 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------