Distributed version of the Spring PetClinic Sample Application built with Spring Cloud for Kubernetes
This microservices branch was initially derived from AngularJS version to demonstrate how to split sample Spring application into microservices. To achieve that goal we used Spring Cloud Netflix technology stack.
Every microservice is a Spring Boot application and can be started locally using IDE or mvn 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).
Tracing server and Admin server startup is optional.
If everything goes well, you can access the following services at given location:
- Discovery Server - http://localhost:8761
- Config Server - http://localhost:8888
- AngularJS frontend (API Gateway) - http://localhost:8080
- Customers, Vets and Visits Services - random port, check Eureka Dashboard
- Tracing Server (Zipkin) - http://localhost:9411/zipkin/
- Admin Server (Spring Boot Admin) - http://localhost:9090
You can tell Config Server to use your local Git repository by using local
Spring profile and setting
GIT_REPO
environment variable, for example:
-Dspring.profiles.active=local -DGIT_REPO=/projects/spring-petclinic-microservices-config
In order to start entire infrastructure using Docker, you have to build images by executing mvn clean install -PbuildDocker
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 wait-for-it.sh
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 Zuul timeouts. You can track services availability using Eureka dashboard
available by default at http://localhost:8761.
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.
You can then access petclinic here: http://localhost:8080/
Our issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues
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 dpom.xml
files.
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/
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 manualy 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.
Spring Cloud components | Resources |
---|---|
Configuration server | Config server properties and Configuration repository |
Service Discovery | Eureka server and Service discovery client |
API Gateway | Zuul reverse proxy and Routing configuration |
Docker Compose | Spring Boot with Docker guide and docker-compose file |
Circuit Breaker | TBD |
Graphite Monitoring | TBD |
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.