4.2 Docker Environment

Setting up your local docker environment for this lab.

Changes to the docker-compose file

Since we are going to use Apache Kafka as a message broker, we need to change our docker-compose.yaml file.

Task 4.2.1 - Set up Apache Kafka

To add a Apache Kafka instance to our docker-compose.yaml file simply add the following services to the file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

  zookeeper:
    image: quay.io/debezium/zookeeper:1.4
    hostname: zookeeper
    container_name: debezium-zookeeper
    networks:
      - kafka
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888

  kafka:
    image: quay.io/puzzle/microservices-lab-debezium-kafka:latest
    hostname: kafka
    container_name: debezium-kafka
    ports:
      - 9092:9092
    networks:
      - kafka
    depends_on:
      - zookeeper
    environment:
      - ZOOKEEPER_CONNECT=zookeeper:2181

Task 4.2.2 - Update your microservice environments

To ensure your microservices will connect to the Kafka broker we need to add an additional property to both of the microservices. The property KAFKA_BOOTSTRAP_SERVERS=kafka:9092 in the environment will ensure that the microservices will connect to our message broker.

Add our kafka-viewer microservice to your docker-compose.yaml. The kafka-viewer is a small web-UI which displays messages passing through our kafka topics.

The definition of the kafka-viewer service should look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  viewer:
    image: quay.io/puzzle/microservices_lab_kafka_viewer:latest
    ports:
      - 8082:8080
    networks:
      - kafka
    depends_on:
      - kafka
    environment:
      - QUARKUS_HTTP_PORT=8080
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_TOPICS=shop-order-request,shop-order-confirmation,shop-order-compensation
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_KEY_DESERIALIZER=org.apache.kafka.common.serialization.StringDeserializer
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_VALUE_DESERIALIZER=org.apache.kafka.common.serialization.StringDeserializer

Task Hint

Your docker-compose.yml should look like this:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
version: '3'

services:
  order-db:
    image: postgres:13
    volumes:
      - order-db-data:/var/lib/postgresql/data/
    networks:
      - kafka
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=1234
    ports:
      - 5432:5432

  order:
    image: quay.io/puzzle/microservices-lab-kafka-order:latest
    ports:
      - 8080:8080
    networks:
      - kafka
    depends_on:
      - order-db
      - kafka
    environment:
      - QUARKUS_HTTP_PORT=8080
      - QUARKUS_DATASOURCE_JDBC_URL=jdbc:tracing:postgresql://order-db:5432/admin
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092

  stock-db:
    image: postgres:13
    volumes:
      - stock-db-data:/var/lib/postgresql/data/
    networks:
      - kafka
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=1234
    ports:
      - 5433:5432

  stock:
    image: quay.io/puzzle/microservices-lab-kafka-stock:latest
    ports:
      - 8081:8080
    networks:
      - kafka
    depends_on:
      - stock-db
      - kafka
    environment:
      - QUARKUS_HTTP_PORT=8080
      - QUARKUS_DATASOURCE_JDBC_URL=jdbc:tracing:postgresql://stock-db:5432/admin
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092

  zookeeper:
    image: quay.io/debezium/zookeeper:1.4
    hostname: zookeeper
    container_name: debezium-zookeeper
    networks:
      - kafka
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888

  kafka:
    image: quay.io/puzzle/microservices-lab-debezium-kafka:latest
    hostname: kafka
    container_name: debezium-kafka
    ports:
      - 9092:9092
    networks:
      - kafka
    depends_on:
      - zookeeper
    environment:
      - ZOOKEEPER_CONNECT=zookeeper:2181

  grafana:
    image: grafana/grafana:latest
    ports:
      - 3000:3000
    networks:
      - kafka
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    volumes:
      - ./config/grafana/dashboards/:/opt/dashboards
      - ./config/grafana/custom.yaml:/etc/grafana/provisioning/dashboards/custom.yaml
      - ./config/grafana/datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yaml

  prometheus:
    image: prom/prometheus:latest
    ports:
      - 9090:9090
    networks:
      - kafka
    volumes:
      - ./config/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml
      - ./config/prometheus/alert.rules:/etc/prometheus/alert.rules

  alertmanager:
    image: prom/alertmanager:latest
    ports:
      - 9093:9093
    networks:
      - kafka
    volumes:
      - ./config/alertmanager/alertmanager.yaml:/etc/alertmanager/alertmanager.yml

  jaeger:
    image: quay.io/jaegertracing/all-in-one:1.24.0
    networks:
      - kafka
    ports:
      - 5775:5775/udp
      - 6831:6831/udp
      - 6832:6832/udp
      - 5778:5778
      - 14268:14268
      - 16686:16686

  viewer:
    image: quay.io/puzzle/microservices_lab_kafka_viewer:latest
    ports:
      - 8082:8080
    networks:
      - kafka
    depends_on:
      - kafka
    environment:
      - QUARKUS_HTTP_PORT=8080
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_TOPICS=shop-order-request,shop-order-confirmation,shop-order-compensation
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_KEY_DESERIALIZER=org.apache.kafka.common.serialization.StringDeserializer
      - MP_MESSAGING_INCOMING_KAFKAMESSAGES_VALUE_DESERIALIZER=org.apache.kafka.common.serialization.StringDeserializer

volumes:
  order-db-data:
  stock-db-data:

networks:
  kafka:
    driver: bridge
    ipam:
      driver: default