diff --git a/kafka-docker/docker-compose.yml b/kafka-docker/docker-compose.yml deleted file mode 100644 index 82e56c7..0000000 --- a/kafka-docker/docker-compose.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: '2' -services: - kafka: - image: wurstmeister/kafka - ports: - - "9092:9092" - environment: - - KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 - - KAFKA_ADVERTISED_PORT=9092 - - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - depends_on: - - zookeeper - zookeeper: - image: wurstmeister/zookeeper - ports: - - "2181:2181" - environment: - - KAFKA_ADVERTISED_HOST_NAME=zookeeper diff --git a/mysql-docker/docker-compose.yml b/mysql-docker/docker-compose.yml deleted file mode 100644 index 72d7565..0000000 --- a/mysql-docker/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '2' -volumes: - data-volume: {} -services: - mysql: - image: mariadb - ports: - - "3306:3306" - environment: - MYSQL_ROOT_PASSWORD: pwd - MYSQL_DATABASE: sample_mysql_db - volumes: - - data-volume:/var/lib/mysql \ No newline at end of file diff --git a/sink/README.md b/sink/README.md index eeab3c2..fd1f97c 100644 --- a/sink/README.md +++ b/sink/README.md @@ -23,19 +23,16 @@ To run this sample, you will need to have installed: The following instructions assume that you are running Kafka and MySql as Docker images. -* Go to the root of the repository -* `cd kafka-docker` +* Go to the application root * `docker-compose up -d` -* Open another terminal and go to the root of the samples repository -* `cd mysql-docker` -* `docker-compose up -d` +* Open another terminal * Ensure that you have the `mysql` CLI tool installed and then use this command: `mysql -u root -p -h 127.0.0.1 -P 3306 sample_mysql_db` `sample_mysql_db` is the name of the database created by the mysql that is running in the docker container. -* Open another terminal and go the root of this sample app (`source`) +* Go back to the other terminal (root of this sample app `sink`) * `./mvnw clean package` When you start the app, it will create a table in the database. @@ -46,6 +43,7 @@ See the method annotated with`PostConstruct` in the application for more details The application has a convenient test source that sends to the same destination on the broker where the sink consumes data from. This test source will send some test records every second. Alternatively, you can connect to the topic using a Kafka console producer and send data in the format - `{"id":1,"name":"Bob","tag":"1}`. +If you go with this kafka console producer approach, make sure you comment out the test source in the sample and rebuild. * Now go to your MySQL CLI: diff --git a/sink/docker-compose.yml b/sink/docker-compose.yml new file mode 100644 index 0000000..604504d --- /dev/null +++ b/sink/docker-compose.yml @@ -0,0 +1,29 @@ +version: '2' +volumes: + data-volume: {} +services: + mysql: + image: mariadb + ports: + - "3306:3306" + environment: + MYSQL_ROOT_PASSWORD: pwd + MYSQL_DATABASE: sample_mysql_db + volumes: + - data-volume:/var/lib/mysql + kafka: + image: wurstmeister/kafka + ports: + - "9092:9092" + environment: + - KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 + - KAFKA_ADVERTISED_PORT=9092 + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + depends_on: + - zookeeper + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + environment: + - KAFKA_ADVERTISED_HOST_NAME=zookeeper \ No newline at end of file diff --git a/kafka-docker/start-kafka-shell.sh b/sink/start-kafka-shell.sh similarity index 100% rename from kafka-docker/start-kafka-shell.sh rename to sink/start-kafka-shell.sh diff --git a/source/README.adoc b/source/README.adoc index 6eae41c..a893aed 100644 --- a/source/README.adoc +++ b/source/README.adoc @@ -35,19 +35,16 @@ Refer to the `application.yml` for the defaults used for the following propertie The following instructions assume that you are running Kafka and MySql as Docker images. -* Go to the root of the repository -* `cd kafka-docker` +* Go to the application root * `docker-compose up -d` -* Open another terminal and go to the root of the samples repository -* `cd mysql-docker` -* `docker-compose up -d` +* Open another terminal * Ensure that you have the `mysql` CLI tool installed and then use this command: `mysql -u root -p -h 127.0.0.1 -P 3306 sample_mysql_db` `sample_mysql_db` is the name of the database created by the mysql that is running in the docker container. -* Open another terminal and go the root of this sample app (`source`) +* Go back to the other terminal (root of this sample app `source`) * `./mvnw clean package` When you start the app, it will insert some test data into the database. diff --git a/source/docker-compose.yml b/source/docker-compose.yml new file mode 100644 index 0000000..604504d --- /dev/null +++ b/source/docker-compose.yml @@ -0,0 +1,29 @@ +version: '2' +volumes: + data-volume: {} +services: + mysql: + image: mariadb + ports: + - "3306:3306" + environment: + MYSQL_ROOT_PASSWORD: pwd + MYSQL_DATABASE: sample_mysql_db + volumes: + - data-volume:/var/lib/mysql + kafka: + image: wurstmeister/kafka + ports: + - "9092:9092" + environment: + - KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 + - KAFKA_ADVERTISED_PORT=9092 + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + depends_on: + - zookeeper + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + environment: + - KAFKA_ADVERTISED_HOST_NAME=zookeeper \ No newline at end of file diff --git a/source/start-kafka-shell.sh b/source/start-kafka-shell.sh new file mode 100755 index 0000000..62663e4 --- /dev/null +++ b/source/start-kafka-shell.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e HOST_IP=$1 -e ZK=$2 -i -t wurstmeister/kafka /bin/bash