martinKindall / node_microservices_and_docker

Just to learn about Docker Compose and how easy is to setup multiple microservices to communicate with each other.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node Microservices with Docker

This is an educative project I made to put into practice my Docker skills for building a simple Orders app. In fact, there is no structure for the data being sent as an order, because that was not the point of this app. The purpouse was to focus on how to make the following microservices interact with each other:

API microservice

This is an express backend that exposes to the users 2 routes: one for saving a new order and another for reading existing orders from the database.

When it receives a request for saving a new order, it sends the data to a Redis channel.

When it receives a request for reading the exising orders, it redirects that request to the DB microservice.

DB microservice

This is another express backend that is only reachable by the API microservice. This microservice is the one in charge of the Database. It receives the GET requests for reading the existing orders in the DB, and makes the query to the DB (Mongo).

It also subscribes to the Redis channel where the new orders are being sent, and saves those into the DB.

Redis microservice

This is just a Redis instance, based on the official Docker Redis image. It is only reachable by the microservices and not by the users.

In this project, Redis is used as a fire and forget Message Broker.

Mongo microservice

This is a MongoDB server based on the Docker MongoDB image. It is only reachable by the microservices and not by the users. The user can read it through the API though.

Mongo-express

This is a Mongo Web based client that is exposed to the users. It is very convenient for checking if the data is being properly written into the DB.

Usage

This project was developed using Windows 10, hence the shared drive in the docker-compose.yml. But this can work on GNU/Linux or OSX too, just change the path of the volume.

I develop in Docker using source files mounted in volumes, this way any change on the source file can be quickly detected by the container without having to build the images again. I still have to do docker-compose stop and docker-compose up to catch the changes, but the amount of time it takes is short compared to building images.

Once in the root of this project, just write:

docker-compose up

And let compose do its magic. The API will be reachable on localhost port 3000. Available routes are

GET /orders

and

POST /orders

with data in JSON as a body.

About

Just to learn about Docker Compose and how easy is to setup multiple microservices to communicate with each other.


Languages

Language:JavaScript 97.1%Language:Dockerfile 2.9%