O'Reilly logo

Microservice Patterns and Best Practices by Vinicius Feitosa Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Coding the microservice

We have the database of the RecommendationService microservice defined and created in our docker-compose.yml file. We will now do the same to create a container for the microservice. Again, let's edit the docker-compose.yml file.

In this code, we have a dependency, the database, and the message broker, besides some definitions of environmental variables, mainly to connect to the database and queues:

    recommendation_service:      image: recommendation_service      build: ./RecommendationService        volumes:          - './RecommendationService:/app'        environment:          - QUEUE_HOST=amqp://guest:guest@rabbitmq          - DATABASE_URL=http://recommendation_db:7474/db/data          - USER_SERVICE_ROUTE=http://172.17.0.1/user/        depends_on:          - recommendation_db - rabbitmq ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required