spring-cloud-demo
Demonstrate micro service architecture implemented using Spring cloud.
There are 6 services in this demo, serving different contents
- config-server: serves configuration to all services
- discovery-server: discovery server implemented using netflix-eureka
- user-service: serves users details
- photo-service: serves photo details
- comment-service: serves photo details
- gateway: Gateway service which provides api's end points and collects content from required services to serves to users
What is Config Server
In cloud environment configuration can be kept centralized. Spring cloud provides config-server which can fetch configuration from version control systems like git or svn and from file system as well. In this demo directory configserver contains config-server which is configured to use this git repository for storing config files. all config files are kept in config folder.
What is discovery-service
Discovery service is responsible for registering and providing
- Location of different services
- Status of different services, whether they are running or is down
In this demo directory discoveryserver contains discovery-service which is implemented using Netflix's Eureka. Spring boot makes it super easy to implement it using
spring-cloud-starter-netflix-eureka-server
.
MySql has been used as database for storing and fetching data. use all.sql file to populate databases. There are three databases:
- User: contains users data
- Photos: contains photo's data
- Comments: contains comment's data
All services uses common module data
and dao
for connecting and fetching data from database.
How to run
First of all build the project using maven from the root of the project. Run below command
maven clean install -DskipTests
Note: By default spring plugin runs the tests as i have added dependencies. Tests will be added later on, so for now skip tests
Run services in below sequence
- Discovery server from discoveryserver directory using command
mvn spring-boot:run
- Config server from configserver directory using command
mvn spring-boot:run
- Now you can run rest services from their respective directories using command
mvn spring-boot:run
Collecting traces using zipkin
This demo is configured to extract trace information using zipkin. Spring cloud provide a utility named slueth
which exports trace information from your service to zipkin which shows the time taken to communicate between different services
Download zipkin from https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec and run using command java -jar zipkin-server-<version>-exec.jar
(replace version or correct jar file name)
Now open Eureka service from url http://localhost:8761/ This should show all registered services Access user's detail from url http://localhost:8080/users. This should return a list of users
Access trace logs from zipkin http://localhost:9411