Coder Social home page Coder Social logo

chinusaraf / uiuc_cs-597_fuzzing-microservices_microservice-consul Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ewolff/microservice-consul

0.0 0.0 0.0 181 KB

Sample of a Microservice setup for my book ported to Consul / Apache httpd. Based on Spring Cloud / Netflix / Java / Docker / Docker Compose / Docker Machine

License: Apache License 2.0

Shell 0.56% Java 76.43% HTML 20.17% Dockerfile 2.84%

uiuc_cs-597_fuzzing-microservices_microservice-consul's Introduction

Microservice Consul Sample

Deutsche Anleitung zum Starten des Beispiels

This sample is like the sample for my Microservices Book (English / German) that you can find at https://github.com/ewolff/microservice .

However, this demo uses Hashicorp Consul for service discovery and Apache httpd as a reverse proxy to route the calls to the services and as a load balancer.

This project creates a complete micro service demo system in Docker containers. The services are implemented in Java using Spring and Spring Cloud.

It uses three microservices:

Consul

Consul has a Web UI. You can access it at port 8500 of your Docker host. Also the homepage at port 8080 contains a link to the Consul UI

Also you can use Consul's DNS interface with e.g. dig:

dig @192.168.99.100 -p 8600  order.service.consul.
dig @192.168.99.100 -p 8600  order.service.consul. ANY
dig @192.168.99.100 -p 8600  order.service.consul. SRV

Note that the demo uses the original Consul Docker image provided by Hashicorp. However, the demo does not use a Consul cluster and only stores the data in memory i.e. it is certainly not fit for production.

All the Spring Cloud microservices (customer, catalog and order) register themselves in the Consul server. An alternative approach to register the services is Registrator. An alternative to using Apache HTTP as a load balancer would e.g. be Fabio.

Apache HTTP Load Balancer

Apache HTTP is used to provide the web page of the demo at port 8080. It also forwards HTTP requests to the microservices whose ports are not exposed! Apache HTTP is configured as a reverse proxy for this - and as a load balancer i.e. if you start multiple instances of a microservices e.g. via docker-compose scale catalog=2, Apache will recognize the new instance.

To configure this Apache HTTP needs to get all registered services from Consul. Consul Template is used for this. It uses a template for the Apache HTTP configuration and fills in the IP addresses of the registered services.

The Docker container therefore runs two processes: Apache HTTP and Consul Template. Consul Template starts Apache httpd and also restarts Apache httpd when new services are registered in the Consul server.

Please refer to the subdirectory apache to see how this works.

Prometheus

Prometheus is a monitoring system. The code of the microservice-consul-demo-order project includes code to export metrics to Prometheus in com.ewolff.microservice.order.prometheus. Also the docker-compose configuration in docker-compose-prometheus.yml includes a Prometheus instance. It will listen on port 9090 on the Docker host. That way you can monitor the application. Run it with docker-compose -f docker-compose-prometheus.yml up -d.

Elastic Stack

The Elastic Stack provides a set of tools to handle log data. The projects contain a Logback configuration in logback-spring.xml so that the services log JSON formatted data.

The docker-compose configuration in docker-compose-elastic.yml includes

  • Filebeat to ship the log from a common volume to Elasticsearch.

  • Elasticsearch to store and analyse the logs.

  • Kibana to analyse the logs. You can access it on port 5601 e.g. at http://localhost:5601. The indices are called filebeat-*.

You can run the configuration with docker-compose -f docker-compose-elastic.yml up -d.

Zipkin

Zipkin is a tool to trace calls across microservices. The project includes all necessary libraries to provide traces.

The docker-compose configuration in docker-compose-zipkin.yml includes

  • A Zipkin server to store and display the data. You can access it on port 9411 e.g. at http://localhost:9411.

  • Microservices are configured to provide trace information.

You can run the configuration with docker-compose -f docker-compose-zipkin.yml up -d.

Technologies

  • Consul for Lookup/ Discovery
  • Apache as a reverse proxy to route calls to the appropriate SCS.
  • Ribbon for client-side Load Balancing. See the classes CatalogClient and CustomerClient in the package com.ewolff.microservice.order.clients in the microservice-demo-order project.

How To Run

The demo can be run with Docker Machine and Docker Compose via docker-compose up

See How to run for details.

Remarks on the Code

The servers for the infrastructure components are pretty simple thanks to Spring Cloud:

The microservices are:

The microservices have a Java main application in src/test/java to run them stand alone. microservice-demo-order uses a stub for the other services then. Also there are tests that use consumer-driven contracts. That is why it is ensured that the services provide the correct interface. These CDC tests are used in microservice-demo-order to verify the stubs. In microservice-demo-customer and microserivce-demo-catalog they are used to verify the implemented REST services.

uiuc_cs-597_fuzzing-microservices_microservice-consul's People

Contributors

cstettler avatar froemra avatar silasmahler 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.