Coder Social home page Coder Social logo

curioustauseef / microservices-design-patterns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rodrigorodrigues/microservices-design-patterns

0.0 0.0 0.0 5.14 MB

Microservice Architecture using multiple languages

Home Page: https://spendingbetter.com

Java 22.93% JavaScript 16.45% HTML 1.62% CSS 1.52% Dockerfile 0.45% Shell 0.86% TypeScript 51.03% Kotlin 4.08% Python 1.05%

microservices-design-patterns's Introduction

Microservice Architecture with Multiple Languages

Build Status codecov

The idea for this project is to show a case for applying Microservice Architecture using multiple languages.

Most all services are built in Java with Spring Boot 2 + Webflux + MongoDB but there are other services using NodeJS, Kotlin and Python.

The web application is using React and also a beta version using JHipster.

Feel free to create a new microservice using a different language(Go?, Ruby?, C#?), just please following the minimal requirements:

  • Create a new folder on root and put your code
  • Add a minimal documentation
  • Add a Rest API
  • Add JWT Validation
  • Add Tests
  • Add Dockerfile
  • Add MongoDB or some other NoSql
  • Add Eureka Client(if possible)
  • Add Spring Cloud Config Client(if possible)

PS: A better approach would be a microservice per repository but for simplicity all microservices are in the same repo.

If you want to contribute please check TODO List.

Inspired by the book Microservices Patterns(Chris Richardson - @crichardson).

Contents

  1. Microservice Patterns
  2. Prerequisites
  3. Microservice Diagram
  4. Installing all services using Docker Compose
  5. Docker Commands
  6. Monitoring - Spring Boot Admin
  7. Service Discovery - Eureka
  8. Externalized Configuration - Spring Config
  9. Prometheus and Grafana
  10. Zipkin Request Tracing
  11. Manual Installation - NOT RECOMMENDED
  12. Accessing React Web App
  13. List of default users
  14. Kubernetes - Google Cloud Platform
  15. Travis CI/CD
  16. Github Actions CI/CD
  17. TODO List
  18. References
  19. Postman Collection

Microservice Patterns

The following list of Microservice Patterns was applied so far.

PS: Used <artifactId>eureka-consul-adapter</artifactId> on eureka-server for scraping data for Prometheus

To know more about each pattern look at Microservice Architecture

Prerequisites

  • JDK 1.8
  • Maven 3
  • Docker 17.05.0-ce+ - Not necessary but recommended otherwise the services should run by command
  • Docker Compose 1.23.2 - Not necessary but recommended otherwise the services should run by command

Microservice Diagram

Microservice Architecture

Installing All Services using Docker Compose

The easiest way to run all microservices is using docker-compose, run the following commands:

On root folder first need to generate the docker images.

# at once for building the docker images
mvn clean install docker:build

Then on docker folder run all microservices using

docker-compose up -d

PS: Whenever change is made on the source code it is necessary to rebuild the image, you can use the following command:

docker-compose up --build week-menu-api react-webapp

Docker Commands

To see logs for a specific docker container:

docker logs -f SERVICE_NAME

PS: Service names are on docker-compose.yml -> container_name

To execute a command inside the container:

docker exec -it week-menu-api sh

To stop and remove all containers:

docker-compose down -v

To restart/start/stop/remove specific container:

docker-compose restart SERVICE_NAME
docker-compose up SERVICE_NAME
docker-compose stop SERVICE_NAME
docker-compose rm SERVICE_NAME

Monitoring - Spring Boot Admin

To see information(environment, instances, logs, etc) related to all microservices registered with Eureka use Spring Boot Admin - http://localhost:9000.

Spring Boot

PS: Need login with a valid user and role ADMIN. See at Default Users

Service Discovery - Eureka

To see all microservices registered with Eureka use http://localhost:8761.

Eureka

PS: Need login with a valid user and role ADMIN. See at Default Users

Externalized Configuration - Spring Cloud Config

To see configuration related to specific service use Spring Config http://localhost:8888/${SERVICE_NAME}/${SPRING_PROFILE}.

Spring Config

PS: Need login with a valid user and role ADMIN. See at Default Users

Prometheus and Grafana

Prometheus is a tool for generating metrics from the requests.

Grafana is a tool for communicate with Prometheus and display the data with dashboards.

Spring Boot 2 by default uses Micrometer for monitoring JVM/Microservices Applications.

To access Prometheus UI

Prometheus

To access Grafana Dashboard.

Grafana

PS: It depends on docker.

Sleuth and Zipkin

Sleuth is used for creating a unique identifier(Span) and set to a request for all microservices calls.

Zipkin is used for request tracing through microservices.

To access Zipkin UI.

Zipkin1 Zipkin2

Manual Installation - NOT RECOMMENDED

If for some reason you cannot install docker/docker-compose you can run all services manually.

On root folder run the following command at once:

mvn clean install

Run Spring Boot

To run the services use the following command in each Microservices folders:

mvn spring-boot:run -Dspring-boot.run.arguments="--server.port={PORT}"

eureka-server - PORT=8761
config-server - PORT=8888
edge-server - PORT=9006
admin-server - PORT=9000
authentication-service - PORT=9999
person-service - PORT=8082
user-service - PORT=8083

PS: To login at Eureka/Config/Edge/Admin need a user with role ADMIN. See at Default Users

Run Node.js service

On nodejs-service folder run the following commands:

sudo npm install

sudo npm start

Run React Web app

On react-webapp folder run the following commands:

sudo npm install

sudo npm start

Accessing React App

To access React Web App.

React1 React2

Default Users

Following the list of default users:

[email protected]/password - ROLE_ADMIN

[email protected]/password123 - ROLE_PERSON_CREATE, ROLE_PERSON_READ, ROLE_PERSON_SAVE

[email protected]/test - ROLE_PERSON_READ

Kubernetes - Google Cloud Platform

The code is deployed at Google Cloud Platform, to access it go through https://spendingbetter.com.

Following useful commands for kubernetes

Installation

#helm create ingress - RBAC enabled
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller
helm list
helm init --tiller-tls-verify
helm init
kubectl get deployments -n kube-system
helm install --name nginx-ingress stable/nginx-ingress --set rbac.create=true --set controller.publishService.enabled=true

#helm list
helm list

#create tls
kubectl create secret tls ingress-tls --cert /etc/sslmate/www.spendingbetter.com.chained.crt --key /etc/sslmate/www.spendingbetter.com.key

#create generic certs
kubectl create secret generic spendingbetter-p12 --from-file=/etc/sslmate/www.spendingbetter.com.p12
kubectl create secret generic spendingbetter-crt --from-file=/etc/sslmate/www.spendingbetter.com.crt

#list certs
kubectl get secrets

#list specific cert
kubectl describe secret ingress-tls

#show ingress
kubectl get ing
kubectl describe ingress


# Istio
# Get Grafana Configuration
kubectl get service grafana --namespace istio-system -o yaml

# Update Grafana Configuration
kubectl edit service grafana --namespace istio-system

Deployment

cd kubernetes

#create docker image
docker tag eureka-server:latest eu.gcr.io/spring-boot-gke-243520/eureka-server:4.0
docker tag docker_react-webapp:latest eu.gcr.io/spring-boot-gke-243520/react-webapp:6.0

#push docker image
docker push eu.gcr.io/spring-boot-gke-243520/eureka-server:4.0
docker push eu.gcr.io/spring-boot-gke-243520/react-webapp:6.0

#Deploy
kubectl apply -f deployment-admin-server.yml

#Undeploy
kubectl delete -f deployment-admin-server.yml

#see logs
kubectl logs admin-server-XXXXX -f

#exec command
kubectl exec -it redis-5b4699dd74-qckm9 -- sh

#show all pods
kubectl get pods --show-labels

#create config map
kubectl create configmap prometheus --from-file=../docker/prometheus-prod.yml

kubectl create configmap grafana-dashboard --from-file=../docker/create-datasource-and-dashboard.sh

kubectl create configmap grafana-datasource --from-file=../docker/grafana-datasource.yaml

#port forward
kubectl port-forward $(kubectl get pod --selector="app=eureka-server" --output jsonpath='{.items[0].metadata.name}') 8761:8761

#delete specific ingress
kubectl delete ingress ingress-gateway-forward-https

#cpu usage
kubectl get nodes --show-labels
kubectl describe nodes gke-your-first-cluster
kubectl top nodes

Enable Ingress

Example Ingress Configuration

Install Helm

Kubernetes + Zuul

Example Spring Boot 2 + Kubernetes + Zuul

Secure Discovery Example

Travis CI/CD

Used travis-ci for building pull requests only.

Github Actions CI/CD

Using GitHub Actions for deploying services into Google Cloud/GKE.

More details of look at .github/workflows/gke-deploy-* for each microservice.

Configuration for Kubernetes was moved to .github/workflows/kubernetes.

Swagger UI

Swagger UI is available for Authentication, Person and User Services

Access it Swagger UI - http://localhost:{SERVICE_PORT}/swagger-ui.html

TODO List

  • Java - Split Person and User in different entities
  • Java - Split back-end and front-end in two different folders
  • Java - Split Java 8 Learning in another folder
  • Java - Add Test for Users Classes
  • Java - Add Spring Cloud Config
  • Java - Add Service Discovery(Eureka)
  • Java - Add Zuul(Gateway)
  • Java - Add Maven Docker Plugin
  • Java - Add Redis for Shared Session between applications
  • Java - Add Authentication for all applications
  • Java - Add Prometheus/Grafana for docker compose
  • Java - Add Oauth2 Security layer
  • Java - Fix Zuul/Edge Server for working with NodeJS Service
  • Kotlin - Add Service using Kotlin Language
  • Scala - Add Service using Scala Language
  • C# - Add Service using C# Language
  • Go - Add Service using Go Language
  • React - Create User List
  • React - Create User Page
  • React - Create User Edit
  • React - Create Categories Edit
  • React - Create Recipes Edit
  • React - Fix User Create/Edit
  • React - Fix Person Create/Edit
  • React - Fix Person List to work with @Tailable and EventSource.
  • React - Fix Docker Web App to use Nginx
  • Kubernetes/Minikube - Add example to use Kubernetes with Minikube
  • Deploy - Google Cloud/GKE
  • CI/CD - Add Travis
  • CI/CD - - Add Herokuy
  • CI/CD - Add GitHub Actions for deploy in GCP
  • Add documentation for libraries used
  • Add documentation/how-to for each language
  • Add tests for Python
  • Add React Legacy

References

Pattern Microservice Architecture

Spring Guide

Spring Boot

React ad Spring WebFlux

Spring WebFlux Security Jwt

Junit 5

Keytool Commands

Spring Boot Kotlin Example

Istio with SDS - Manual Instalation

Istio on GKE

Istio Gateway

Automatic Deployment using Travis and GKE

microservices-design-patterns's People

Contributors

dependabot[bot] avatar luizgrp avatar rodrigorodrigues avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.