Making the containers work together

First, we have to delete the old instance of MongoDB in the docker-compose.yml file that was being shared in the Shared design pattern. This instance will have no more use for us because each of the News microservices will have their own database. Let's remove the old code:

mongo:
image: mongo:latest
container_name: "mongodb"
ports:
- 27017:27017
command: mongod --smallfiles --logpath=/dev/null # --quiet

After we remove the common container Mongo, we will create our RabbitMQ container, which served as the message broker to our microservices.

In the root directory of our project, we will create a new directory called queue. Inside the queue directory, let's create a Dockerfile with the following configuration:

FROM rabbitmq:3-management 
ENV RABBITMQ_ERLANG_COOKIE: "random string" 
ENV RABBITMQ_DEFAULT_USER: "guest" 
ENV RABBITMQ_DEFAULT_PASS: "guest" 
ENV RABBITMQ_DEFAULT_VHOST: "/" 

After the creation of the Dockerfile, we will go back to the docker-compose.yml file and write the configuration container. RabbitMQ for the container exposes two ports—the 5672 port, used by the tool for the job of communicating, and the 15672 port, used to access the administrative tool in RabbitMQ:

rabbitmq: 
    image: rabbitmq 
    build: ./queue 
    ports: 
        - "15672:15672" 
        - "5672:5672" 
    restart: Always 

It is time we set the instance of our orchestrator. The highlight of this configuration is due to the dependency declaration with microservices of News and the message broker:

orchestrator_news_service: 
    image: orchestrator_news_service 
    build: ./NewsOrchestrator 
    volumes: 
      - './NewsOrchestrator:/app' 
    environment: 
      - APP_SETTINGS=config.DevelopmentConfig 
      - QUEUE_HOST=amqp://guest:guest@rabbitmq 
    depends_on: 
      - famous_news_service 
      - politics_news_service 
      - sports_news_service 
      - rabbitmq 
    links: 
      - famous_news_service 
      - politics_news_service 
      - sports_news_service 
      - rabbitmq 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.109.21