• Stars
    star
    104
  • Rank 329,792 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

microservice

Sample of a Microservice setup for my book. Based on Spring Cloud / Netflix / Java / Docker / Docker Compose / Docker Machine / Vagrant
Java
712
star
2

microservice-kafka

Demo to show how Apache Kafka can be used for communication between microservices
Java
579
star
3

microservice-kubernetes

Microservices example using Kubernetes
Java
201
star
4

microservice-istio

Example for a microservices system based in Kubernetes and the service mesh Istio
Java
185
star
5

user-registration

Continuous Delivery example: Chef, Docker, Jenkins, Graphite, ELK stack, jBehave, Selenium, Gatling
Ruby
65
star
6

InformatikFAQ

Informatik als Beruf FAQ
51
star
7

SCS-ESI

Demo for Self-contained Systems (SCS) using ESI (Edge Side Includes) with Varnish for Frontend Integration
Java
44
star
8

user-registration-V2

Java
38
star
9

spring-boot-demos

Some demos for Spring Boot
Java
38
star
10

microservice-atom

Demo to show how Atom can be used for communication between microservices
Java
31
star
11

microservice-consul-dns

Microservices Demo. Uses Consul as DNS server, registration is automated using Registrator
Java
21
star
12

microservice-linkerd

Microservices example with Linkerd service mesh
Java
16
star
13

crimson-assurance-demo

Demo for frontend integration
Dockerfile
14
star
14

cheatsheets-DE

Kurze Ãœbersichten / Cheatsheets zu Maven und Docker
14
star
15

microservice-spring

A microservices sample using Spring Boot features
Java
14
star
16

scala-spring

Shows how Scala and Spring can be integrated
Scala
12
star
17

microservice-cloudfoundry

Microservices demo using Cloud Foundry
Java
12
star
18

software-architektur.tv

software-architektur.tv Website
CSS
10
star
19

SCS-jQuery

Demo for Self-contained Systems (SCS) using jQuery for Frontend Integration
Java
9
star
20

microservices-rezepte

Source für Broschüre "Microservices Rezepte"
9
star
21

Spring-Integration-Web-Services-Batch-Demo

Demo of Spring Web Services, Spring Batch and Spring Integration
Java
8
star
22

microservices-primer

Source for booklet "Microservices Primer"
Shell
8
star
23

microservice-dapr

A microservices sample using Dapr
Java
7
star
24

spring-redis-demo

Shows how Spring can be used to access the Redis NoSQL store
Java
6
star
25

bildungsinitiativen

List von verschiedenen Bildungsinitiativen im Bereich Software-Entwicklung
5
star
26

docker-java

Very small Java image for Docker
5
star
27

microservices-vm

Creates a virtual machine with the Microservices demo and the Continuous Delivery demo
Shell
4
star
28

microservices-ueberblick

Source für Broschüre "Microservices Überblick"
4
star
29

lvm-demo

LVM Demo shows principles of ROCA and SCS
3
star
30

Spring-Buch

Repository for the Spring book (German)
Java
2
star
31

ewolff.com

Eberhard Wolff's Homepage
CSS
2
star
32

service-mesh-primer

Source for booklet "Service Mesh Primer"
Makefile
2
star
33

seneca-example

A simple example using the Seneca framework
JavaScript
2
star
34

practical-microservices.com

XSLT
2
star
35

microservices-recipes

Source for booklet "Microservices Recipes"
2
star
36

spring-buch.de

Website für das Spring Buch
HTML
1
star
37

JavaChefVagrantEC2

Ruby
1
star
38

spring-rabbit-demo

Demo how to use Spring AMQP and RabbitMQ
Java
1
star
39

microservices-buch.de

Website für das Microservices Buch
XSLT
1
star
40

redis-docker

Redis installation with Docker
Shell
1
star
41

news-application-heroku

Java
1
star
42

war-demo

Demo for Nanoservices using WARs and Tomcat
Java
1
star
43

microservices-praxisbuch.de

XSLT
1
star
44

continuous-delivery-buch.de

Website für das Continuous Delivery Buch
XSLT
1
star
45

erlang-example

Simple example for an Erlang client / server
Erlang
1
star