|
| 1 | +# Distributed version of the Spring PetClinic Sample Application built with Spring Cloud |
| 2 | + |
| 3 | +[](https://travis-ci.org/spring-petclinic/spring-petclinic-microservices/) [](https://opensource.org/licenses/Apache-2.0) |
| 4 | + |
| 5 | +This microservices branch was initially derived from [AngularJS version](https://github.com/spring-petclinic/spring-petclinic-angular1) to demonstrate how to split sample Spring application into [microservices](http://www.martinfowler.com/articles/microservices.html). |
| 6 | +To achieve that goal we use Spring Cloud Gateway, Spring Cloud Circuit Breaker, Spring Cloud Config, Spring Cloud Sleuth, Resilience4j, Micrometer |
| 7 | +and the Eureka Service Discovery from the [Spring Cloud Netflix](https://github.com/spring-cloud/spring-cloud-netflix) technology stack. |
| 8 | + |
| 9 | +## Starting services locally without Docker |
| 10 | + |
| 11 | +Every microservice is a Spring Boot application and can be started locally using IDE or `../mvnw spring-boot:run` command. Please note that supporting services (Config and Discovery Server) must be started before any other application (Customers, Vets, Visits and API). |
| 12 | +Startup of Tracing server, Admin server, Grafana and Prometheus is optional. |
| 13 | +If everything goes well, you can access the following services at given location: |
| 14 | +* Discovery Server - http://localhost:8761 |
| 15 | +* Config Server - http://localhost:8888 |
| 16 | +* AngularJS frontend (API Gateway) - http://localhost:8080 |
| 17 | +* Customers, Vets and Visits Services - random port, check Eureka Dashboard |
| 18 | +* Tracing Server (Zipkin) - http://localhost:9411/zipkin/ (we use [openzipkin](https://github.com/openzipkin/zipkin/tree/master/zipkin-server)) |
| 19 | +* Admin Server (Spring Boot Admin) - http://localhost:9090 |
| 20 | +* Grafana Dashboards - http://localhost:3000 |
| 21 | +* Prometheus - http://localhost:9091 |
| 22 | + |
| 23 | +You can tell Config Server to use your local Git repository by using `native` Spring profile and setting |
| 24 | +`GIT_REPO` environment variable, for example: |
| 25 | +`-Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config` |
| 26 | + |
| 27 | +## Starting services locally with docker-compose |
| 28 | +In order to start entire infrastructure using Docker, you have to build images by executing `./mvnw clean install -P buildDocker` |
| 29 | +from a project root. Once images are ready, you can start them with a single command |
| 30 | +`docker-compose up`. Containers startup order is coordinated with [`dockerize` script](https://github.com/jwilder/dockerize). |
| 31 | +After starting services it takes a while for API Gateway to be in sync with service registry, |
| 32 | +so don't be scared of initial Spring Cloud Gateway timeouts. You can track services availability using Eureka dashboard |
| 33 | +available by default at http://localhost:8761. |
| 34 | + |
| 35 | +The `master` branch uses an Alpine linux with JRE 8 as Docker base. You will find a Java 11 version in the `release/java11` branch. |
| 36 | + |
| 37 | +*NOTE: Under MacOSX or Windows, make sure that the Docker VM has enough memory to run the microservices. The default settings |
| 38 | +are usually not enough and make the `docker-compose up` painfully slow.* |
| 39 | + |
| 40 | +## Understanding the Spring Petclinic application |
| 41 | + |
| 42 | +[See the presentation of the Spring Petclinic Framework version](http://fr.slideshare.net/AntoineRey/spring-framework-petclinic-sample-application) |
| 43 | + |
| 44 | +[A blog bost introducing the Spring Petclinic Microsevices](http://javaetmoi.com/2018/10/architecture-microservices-avec-spring-cloud/) (french language) |
| 45 | + |
| 46 | +You can then access petclinic here: http://localhost:8080/ |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +**Architecture diagram of the Spring Petclinic Microservices with CosmosDB** |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +## In case you find a bug/suggested improvement for Spring Petclinic Microservices |
| 55 | + |
| 56 | +Our issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues |
| 57 | + |
| 58 | +## Custom metrics monitoring |
| 59 | + |
| 60 | +Grafana and Prometheus are included in the `docker-compose.yml` configuration, and the public facing applications |
| 61 | +have been instrumented with [MicroMeter](https://micrometer.io) to collect JVM and custom business metrics. |
| 62 | + |
| 63 | +A JMeter load testing script is available to stress the application and generate metrics: [petclinic_test_plan.jmx](spring-petclinic-api-gateway/src/test/jmeter/petclinic_test_plan.jmx) |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +### Using Prometheus |
| 68 | + |
| 69 | +* Prometheus can be accessed from your local machine at http://localhost:9091 |
| 70 | + |
| 71 | +### Using Grafana with Prometheus |
| 72 | + |
| 73 | +* An anonymous access and a Prometheus datasource are setup. |
| 74 | +* A `Spring Petclinic Metrics` Dashboard is available at the URL http://localhost:3000/d/69JXeR0iw/spring-petclinic-metrics. |
| 75 | +You will find the JSON configuration file here: [docker/grafana/dashboards/grafana-petclinic-dashboard.json](). |
| 76 | +* You may create your own dashboard or import the [Micrometer/SpringBoot dashboard](https://grafana.com/dashboards/4701) via the Import Dashboard menu item. |
| 77 | +The id for this dashboard is `4701`. |
| 78 | + |
| 79 | +### Custom metrics |
| 80 | +Spring Boot registers a lot number of core metrics: JVM, CPU, Tomcat, Logback... |
| 81 | +The Spring Boot auto-configuration enables the instrumentation of requests handled by Spring MVC. |
| 82 | +All those three REST controllers `OwnerResource`, `PetResource` and `VisitResource` have been instrumented by the `@Timed` Micrometer annotation at class level. |
| 83 | + |
| 84 | +* `customers-service` application has the following custom metrics enabled: |
| 85 | + * @Timed: `petclinic.owner` |
| 86 | + * @Timed: `petclinic.pet` |
| 87 | +* `visits-service` application has the following custom metrics enabled: |
| 88 | + * @Timed: `petclinic.visit` |
| 89 | + |
| 90 | +## Looking for something in particular? |
| 91 | + |
| 92 | +| Spring Cloud components | Resources | |
| 93 | +|---------------------------------|------------| |
| 94 | +| Configuration server | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository] | |
| 95 | +| Service Discovery | [Eureka server](spring-petclinic-discovery-server) and [Service discovery client](spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java) | |
| 96 | +| API Gateway | [Spring Cloud Gateway starter](spring-petclinic-api-gateway/pom.xml) and [Routing configuration](/spring-petclinic-api-gateway/src/main/resources/application.yml) | |
| 97 | +| Docker Compose | [Spring Boot with Docker guide](https://spring.io/guides/gs/spring-boot-docker/) and [docker-compose file](docker-compose.yml) | |
| 98 | +| Circuit Breaker | [Resilience4j fallback method](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java) | |
| 99 | +| Grafana / Prometheus Monitoring | [Micrometer implementation](https://micrometer.io/), [Spring Boot Actuator Production Ready Metrics] | |
| 100 | + |
| 101 | + Front-end module | Files | |
| 102 | +|-------------------|-------| |
| 103 | +| Node and NPM | [The frontend-maven-plugin plugin downloads/installs Node and NPM locally then runs Bower and Gulp](spring-petclinic-ui/pom.xml) | |
| 104 | +| Bower | [JavaScript libraries are defined by the manifest file bower.json](spring-petclinic-ui/bower.json) | |
| 105 | +| Gulp | [Tasks automated by Gulp: minify CSS and JS, generate CSS from LESS, copy other static resources](spring-petclinic-ui/gulpfile.js) | |
| 106 | +| Angular JS | [app.js, controllers and templates](spring-petclinic-ui/src/scripts/) | |
| 107 | + |
| 108 | + |
| 109 | +## Interesting Spring Petclinic forks |
| 110 | + |
| 111 | +The Spring Petclinic master branch in the main [spring-projects](https://github.com/spring-projects/spring-petclinic) |
| 112 | +GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf. |
| 113 | + |
| 114 | +This [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices/) project is one of the [several forks](https://spring-petclinic.github.io/docs/forks.html) |
| 115 | +hosted in a special GitHub org: [spring-petclinic](https://github.com/spring-petclinic). |
| 116 | +If you have a special interest in a different technology stack |
| 117 | +that could be used to implement the Pet Clinic then please join the community there. |
| 118 | + |
| 119 | + |
| 120 | +# Contributing |
| 121 | + |
| 122 | +The [issue tracker](https://github.com/spring-petclinic/spring-petclinic-microservices/issues) is the preferred channel for bug reports, features requests and submitting pull requests. |
| 123 | + |
| 124 | +For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <http://editorconfig.org>. |
| 125 | + |
| 126 | + |
| 127 | +[Configuration repository]: https://github.com/spring-petclinic/spring-petclinic-microservices-config |
| 128 | +[Spring Boot Actuator Production Ready Metrics]: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html |
0 commit comments