Skip to content

relsayed8205/microservices-sample

 
 

Repository files navigation

Microservices Sample

Build Status Docker Repository on Quay Docker Repository on Quay Docker Repository on Quay Docker Repository on Quay

Microservices Sample

What is it?

"Microservices", a trending buzz word nowadays. What problems does it solve?

Many organizations nowadays are driving the technology migrations and one of the biggest challenges is to migrate from monolithic application to micro-services based application.

This microservices-sample project demonstrates how multiple services run independently leveraging on the best microservices patterns to enable scale, performance and resilience.

https://www.youtube.com/watch?v=AYcsnuIOW2M

Use case

The sample application has two services namely service-one and service-two. Each of the service has its own database service-one-db and service-two-db respectively. During the startup of the services, it persists the service name and an auto generated UUID in its perspective database and sends the data to the RabbitMQ exchange which then broadcasts the data to all the queues based on the routing key. Every microservices listens to its own RabbitMQ queue and keeps updating the database as and when it receives the data.

Below are the screens of the application.

alt tag

Clicking on the tab's one or two the data that you see on the screen is based on the data fetched by the respective service by calling its database.

alt tag

Notice that the UUID generated for service-one which lies in service-one-db is in sync with service-two tab which is achieved by RabbitMQ (asychronous communication between microservices).

alt tag

Service Registration

During the initialization of a service, it would get registered to the discovery and registration server (which in our example is Hashicorp's Consul).

alt tag

Service Discovery

When one service (say api-gateway) needs to access a resource from another service (say service-one), all it has to do is ask discovery and registration server (Consul) to give one of the service-one's instance information.

alt tag

Architecture

Below is the architectural diagram for microservices sample project.

alt tag

Components Integrated & Tools Usage

API Gateway

Netflix Zuul is a the reverse proxy server which acts as the API Gateway for accessing the micro services behind the gateway which routes the request to the respective service. Microservice’s stay behind reverse proxy server and needs to be consumed via api gateway. The api-gateway micro service with docker profile runs on port 8080 and can be accessed by http://localhost:8080 .

Configuration done in API Gateway for Routing:

zuul:
  ignoredServices: '*'
  routes:
    one:
      path: /service-one/**
      serviceId: Service-One
    two:
      path: /service-two/**
      serviceId: Service-Two
Service registration and discovery

Registration and discovery is taken care by the HashiCorp’s Consul. During the startup of the individual services, they register with service registration service those details such as host name, port etc. by which the services can be accessed. Once the service is registered to the consul, consul checks for the health of the service by sending a heartbeat for the health check path and health check interval that has been registered with Consul. Requests to the micro-services has to be routed through api-gateway during with the api-gateway contacts discovery service to get the information required to send the request to the intended microservice.

Configuration done in micro services to register to Consul:

management:
  contextPath: /actuator

spring:
  application.name: service-one
  cloud:
    consul:
      host: consul
      port: 8500
      discovery:
        hostName: service-one
        instanceId:${spring.application.name}:${spring.application.instance_id:${random.value}}
        healthCheckPath: ${management.contextPath}/health
        healthCheckInterval: 15s

Consul management console can be accessed at http://localhost:8500/ui/

alt tag

Monitoring and vizualization

Monitoring, visualisation & management of the container in docker is done by weave scope.

Weavescope management console can be accessed at http://localhost:4040/

alt tag

Centralized logging using ELK

Logback integrated with every microservices creates application logs and send the log data to the logging server (Logstash). Logstash formats the data and send it to the indexing server (Elasticsearch). The data stored in elasticsearch server can be beautifully visualized using Kibana.

Accessing tools:

Elasticsearch: http://localhost:9200/_search?pretty

Kibana: http://localhost:5601/app/kibana

alt tag

Asynchronous microservices communication

Intercommunication between microservices happens asynchronously with the help of RabbitMQ.

RabbitMQ console can be accessed at http://localhost:15672/

alt tag

Technology

Microservices sample project uses a number of open source projects to work properly:

Tools

Development

Below are the steps to bring up the development environment and get started.

  1. Install Git, Java, Maven and Docker
  2. For the project using https://github.com/vmudigal/microservices-sample.git
  3. Clone the fork using https://github.com/{YOUR_GIT_ID}/microservices-sample.git
  4. Execute "cd /microservices-sample/build/docker/scripts/"
  5. To deploy docker please run "./deploy.sh docker".
  6. Access the Application at http://localhost/

Extras

Mysql on service-two-db:

$ docker exec -it service-two-db mysql -u service-two -p
Enter password: service-two

mysql> USE service-two;
Database changed

mysql> SELECT * FROM name_value;

Help

Feel free to reach "[email protected]" incase of any concerns.

About

Sample project to create an application using microservices architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 42.5%
  • HTML 20.8%
  • TypeScript 17.4%
  • JavaScript 14.8%
  • Dockerfile 2.3%
  • CSS 1.6%
  • Shell 0.6%