Skip to content
Distributed version of Spring Petclinic built with Spring Cloud
Java HTML JavaScript CSS TSQL Dockerfile
Branch: master
Clone or download

Latest commit

Latest commit a0a6b0a May 12, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.mvn/wrapper Upgrade Maven wrapper to 3.5.4 May 6, 2019
docker Do not download dockerize, use docker caches - fixes #136 (#148) Mar 21, 2020
docs Customize the Grafana container with a custom metrics dashboard Mar 19, 2019
spring-petclinic-admin-server Upgrade to Spring Cloud Hoxton.RELEASE and Spring Boot 2.2.1.RELEASE (#… Mar 14, 2020
spring-petclinic-api-gateway Remove the @EnableCircuitBreaker annotation from test #117 Nov 21, 2019
spring-petclinic-config-server Upgrade to Spring Cloud Hoxton.RC2 and Spring Boot 2.2.1.RELEASE Nov 17, 2019
spring-petclinic-customers-service Upgrade to Spring Cloud Hoxton.RC2 and Spring Boot 2.2.1.RELEASE Nov 17, 2019
spring-petclinic-discovery-server Upgrade to Spring Cloud Hoxton.RC2 and Spring Boot 2.2.1.RELEASE Nov 17, 2019
spring-petclinic-vets-service Upgrade to Spring Cloud Hoxton.RC2 and Spring Boot 2.2.1.RELEASE Nov 17, 2019
spring-petclinic-visits-service Upgrade to Spring Cloud Hoxton.RC2 and Spring Boot 2.2.1.RELEASE Nov 17, 2019
.editorconfig Replace .tern-project by .editorconfig Oct 24, 2016
.gitignore Switch to Java 11 May 6, 2019
.travis.yml Switch to openjdk8 Aug 29, 2019
LICENSE Upgrade to Spring Cloud Hoxton.RELEASE and Spring Boot 2.2.1.RELEASE (#… Mar 14, 2020
README.md IDE need Lombok installed #150 May 12, 2020
docker-compose.yml Remove Hystrix Dashboard #117 Nov 20, 2019
mvnw Upgrade Maven wrapper to 3.5.4 May 6, 2019
mvnw.cmd Upgrade Maven wrapper to 3.5.4 May 6, 2019
pom.xml Upgrade to Spring Cloud Hoxton.RELEASE and Spring Boot 2.2.1.RELEASE (#… Mar 14, 2020

README.md

Distributed version of the Spring PetClinic Sample Application built with Spring Cloud

Build Status License

This microservices branch was initially derived from AngularJS version to demonstrate how to split sample Spring application into microservices. To achieve that goal we use Spring Cloud Gateway, Spring Cloud Circuit Breaker, Spring Cloud Config, Spring Cloud Sleuth, Resilience4j, Micrometer and the Eureka Service Discovery from the Spring Cloud Netflix technology stack.

Starting services locally without Docker

Every microservice is a Spring Boot application and can be started locally using IDE (Lombok plugin has to be set up) 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). Startup of Tracing server, Admin server, Grafana and Prometheus is optional. If everything goes well, you can access the following services at given location:

You can tell Config Server to use your local Git repository by using native Spring profile and setting GIT_REPO environment variable, for example: -Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config

Starting services locally with docker-compose

In order to start entire infrastructure using Docker, you have to build images by executing ./mvnw clean install -P buildDocker from a project root. Once images are ready, you can start them with a single command docker-compose up. Containers startup order is coordinated with dockerize script. After starting services it takes a while for API Gateway to be in sync with service registry, so don't be scared of initial Spring Cloud Gateway timeouts. You can track services availability using Eureka dashboard available by default at http://localhost:8761.

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.

NOTE: Under MacOSX or Windows, make sure that the Docker VM has enough memory to run the microservices. The default settings are usually not enough and make the docker-compose up painfully slow.

Understanding the Spring Petclinic application

See the presentation of the Spring Petclinic Framework version

A blog bost introducing the Spring Petclinic Microsevices (french language)

You can then access petclinic here: http://localhost:8080/

Spring Petclinic Microservices screenshot

Architecture diagram of the Spring Petclinic Microservices

Spring Petclinic Microservices architecture

In case you find a bug/suggested improvement for Spring Petclinic Microservices

Our issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues

Database configuration

In its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed. Dependency for Connector/J, the MySQL JDBC driver is already included in the pom.xml files.

Start a MySql database

You may start a MySql database with docker:

docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8

or download and install the MySQL database (e.g., MySQL Community Server 5.7 GA), which can be found here: https://dev.mysql.com/downloads/

Use the Spring 'mysql' profile

To use a MySQL database, you have to start 3 microservices (visits-service, customers-service and vets-services) with the mysql Spring profile. Add the --spring.profiles.active=mysql as programm argument.

By default, at startup, database schema will be created and data will be populated. You may also manually create the PetClinic database and data by executing the "db/mysql/{schema,data}.sql" scripts of each 3 microservices. In the application.yml of the Configuration repository, set the initialization-mode to never.

If you are running the microservices with Docker, you have to add the mysql profile into the (Dockerfile)[docker/Dockerfile]:

ENV SPRING_PROFILES_ACTIVE docker,mysql

In the mysql section of the application.yml from the Configuration repository, you have to change the host and port of your MySQL JDBC connection string.

Custom metrics monitoring

Grafana and Prometheus are included in the docker-compose.yml configuration, and the public facing applications have been instrumented with MicroMeter to collect JVM and custom business metrics.

A JMeter load testing script is available to stress the application and generate metrics: petclinic_test_plan.jmx

Grafana metrics dashboard

Using Prometheus

Using Grafana with Prometheus

Custom metrics

Spring Boot registers a lot number of core metrics: JVM, CPU, Tomcat, Logback... The Spring Boot auto-configuration enables the instrumentation of requests handled by Spring MVC. All those three REST controllers OwnerResource, PetResource and VisitResource have been instrumented by the @Timed Micrometer annotation at class level.

  • customers-service application has the following custom metrics enabled:
    • @Timed: petclinic.owner
    • @Timed: petclinic.pet
  • visits-service application has the following custom metrics enabled:
    • @Timed: petclinic.visit

Looking for something in particular?

Spring Cloud components Resources
Configuration server Config server properties and Configuration repository
Service Discovery Eureka server and Service discovery client
API Gateway Spring Cloud Gateway starter and Routing configuration
Docker Compose Spring Boot with Docker guide and docker-compose file
Circuit Breaker Resilience4j fallback method
Grafana / Prometheus Monitoring Micrometer implementation, Spring Boot Actuator Production Ready Metrics
Front-end module Files
Node and NPM The frontend-maven-plugin plugin downloads/installs Node and NPM locally then runs Bower and Gulp
Bower JavaScript libraries are defined by the manifest file bower.json
Gulp Tasks automated by Gulp: minify CSS and JS, generate CSS from LESS, copy other static resources
Angular JS app.js, controllers and templates

Interesting Spring Petclinic forks

The Spring Petclinic master branch in the main spring-projects GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf.

This spring-petclinic-microservices project is one of the several forks hosted in a special GitHub org: spring-petclinic. If you have a special interest in a different technology stack that could be used to implement the Pet Clinic then please join the community there.

Contributing

The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.

For pull requests, editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

You can’t perform that action at this time.