├── .gitignore
├── README.md
├── book-service-client
├── pom.xml
└── src
│ └── main
│ ├── docker
│ ├── Dockerfile
│ └── run.sh
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── bookserviceclient
│ │ ├── app
│ │ └── BookServiceClientApplication.java
│ │ ├── client
│ │ └── ServiceClient.java
│ │ └── controller
│ │ └── BookService.java
│ └── resources
│ ├── bootstrap.yml
│ └── logging.properties
├── book-service
├── pom.xml
└── src
│ └── main
│ ├── docker
│ ├── Dockerfile
│ └── run.sh
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── bookservice
│ │ ├── app
│ │ └── BookServiceApplication.java
│ │ └── controller
│ │ └── BookService.java
│ └── resources
│ └── bootstrap.yml
├── build_and_run.sh
├── config-server
├── pom.xml
└── src
│ └── main
│ ├── docker
│ └── Dockerfile
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── configserver
│ │ └── app
│ │ └── ConfigServiceApplication.java
│ └── resources
│ ├── application.yml
│ └── configs
│ ├── application.yml
│ ├── book-service-client.yml
│ ├── book-service.yml
│ ├── hystrix-dashboard.yml
│ ├── zipkin.yml
│ └── zuul-proxy.yml
├── discovery-server
├── pom.xml
└── src
│ └── main
│ ├── docker
│ └── Dockerfile
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── discovery
│ │ └── app
│ │ └── DiscoveryServerApplication.java
│ └── resources
│ └── bootstrap.yml
├── docker-clean.sh
├── docker-compose.yml
├── etc
├── architecture.odg
└── architecture.png
├── hystrix-dashboard
├── pom.xml
└── src
│ └── main
│ ├── docker
│ ├── Dockerfile
│ └── run.sh
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── hystrixdashboard
│ │ └── app
│ │ └── HystrixDashboardApplication.java
│ └── resources
│ └── bootstrap.yml
├── start-only-config-server.sh
├── zipkin
├── pom.xml
└── src
│ └── main
│ ├── docker
│ ├── Dockerfile
│ └── run.sh
│ ├── java
│ └── com
│ │ └── demoapp
│ │ └── zipkin
│ │ └── app
│ │ └── ZipkinApplication.java
│ └── resources
│ └── bootstrap.yml
└── zuul-proxy
├── pom.xml
└── src
└── main
├── docker
├── Dockerfile
└── run.sh
├── java
└── com
│ └── demoapp
│ └── zuulproxy
│ ├── app
│ └── ZuulProxyApplication.java
│ └── proxy
│ └── AccessLogFilter.java
└── resources
└── bootstrap.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.project
2 | *.DS_Store
3 | *.classpath
4 | */target/*
5 | */.settings/*
6 | .idea/
7 | **/*.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simple Spring (Netflix) Cloud Native Microservice Project
2 |
3 | ## Architecture
4 |
5 | 
6 |
7 | ## Requirements
8 |
9 | - Maven 3
10 | - Docker
11 | - Java 8
12 | - docker-compose
13 |
14 | ## Run
15 |
16 | Only run from command line:
17 |
18 | > ./build_and_run.sh
19 |
20 | ## URL Endpoints
21 |
22 | - Direct url to book-service http://localhost:8081/mybooks-public
23 |
24 | - Url to service over zuul proxy http://localhost:9999/book-service-client/mybooks-public
25 |
26 | user credentials
27 |
28 | - username: user
29 | - password: pass
30 |
31 | - Discovery Server
32 |
33 | http://localhost:8761/
34 |
35 | - Zipkin
36 |
37 | http://localhost:9411
38 |
--------------------------------------------------------------------------------
/book-service-client/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | book-service-client
6 | book-service-client
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 |
17 | UTF-8
18 | 1.8
19 | app1_book-service-client
20 | v1
21 |
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-starter-feign
27 |
28 |
29 | org.springframework.cloud
30 | spring-cloud-starter-eureka
31 |
32 |
33 | com.fasterxml.jackson.core
34 | jackson-databind
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-sleuth-zipkin
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-starter-config
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-starter-actuator
55 |
56 |
57 | org.springframework.cloud
58 | spring-cloud-starter-hystrix
59 |
60 |
61 |
62 |
63 |
64 |
65 | org.springframework.cloud
66 | spring-cloud-starter-parent
67 | Camden.SR5
68 | pom
69 | import
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.springframework.boot
78 | spring-boot-maven-plugin
79 |
80 |
81 | com.spotify
82 | docker-maven-plugin
83 | 0.4.13
84 |
85 | ${docker.image.name}:${docker.image.tag}
86 | src/main/docker
87 |
88 |
89 | /
90 | ${project.build.directory}
91 | ${project.build.finalName}.jar
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/book-service-client/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y netcat
3 | VOLUME /tmp
4 | ADD book-service-client-0.0.1-SNAPSHOT.jar app.jar
5 | RUN sh -c 'touch /app.jar'
6 | ADD run.sh run.sh
7 | RUN chmod +x run.sh
8 | CMD ./run.sh
--------------------------------------------------------------------------------
/book-service-client/src/main/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "********************************************************"
4 | echo "Waiting for the configuration server to start on port $CONFIGSERVER_PORT"
5 | echo "********************************************************"
6 | while ! `nc -z $CONFIGSERVER_HOST $CONFIGSERVER_PORT`; do sleep 3; done
7 | echo "******* Configuration Server has started"
8 |
9 | echo "********************************************************"
10 | echo "Starting book-service-client "
11 | echo "********************************************************"
12 | java -Dspring.profiles.active=docker -jar app.jar
13 |
--------------------------------------------------------------------------------
/book-service-client/src/main/java/com/demoapp/bookserviceclient/app/BookServiceClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.bookserviceclient.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
7 | import org.springframework.cloud.netflix.feign.EnableFeignClients;
8 | import org.springframework.cloud.netflix.hystrix.EnableHystrix;
9 | import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.context.annotation.ComponentScan;
12 |
13 | @SpringBootApplication
14 | @EnableEurekaClient
15 | @EnableFeignClients(basePackages = {"com.demoapp.bookserviceclient.client"})
16 | @EnableHystrix
17 | @EnableCircuitBreaker
18 | @ComponentScan(basePackages = {"com.demoapp.bookserviceclient.controller"})
19 | public class BookServiceClientApplication {
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(BookServiceClientApplication.class, args);
23 | }
24 |
25 | @Bean
26 | public AlwaysSampler defaultSampler() {
27 | return new AlwaysSampler();
28 | }
29 | }
--------------------------------------------------------------------------------
/book-service-client/src/main/java/com/demoapp/bookserviceclient/client/ServiceClient.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.bookserviceclient.client;
2 |
3 | import org.springframework.cloud.netflix.feign.FeignClient;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | @FeignClient("book-service")
7 | public interface ServiceClient {
8 |
9 | @RequestMapping("/mybooks")
10 | String mybooks();
11 | }
--------------------------------------------------------------------------------
/book-service-client/src/main/java/com/demoapp/bookserviceclient/controller/BookService.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.bookserviceclient.controller;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import com.demoapp.bookserviceclient.client.ServiceClient;
10 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
11 |
12 | @RestController
13 | public class BookService {
14 |
15 | private Logger logger = LoggerFactory.getLogger(BookService.class);
16 |
17 | @Autowired
18 | private ServiceClient serviceClient;
19 |
20 | @HystrixCommand(fallbackMethod = "mybooksFallback")
21 | @RequestMapping("/mybooks-public")
22 | public String mybooks() {
23 | logger.info("mybooks-public service called");
24 | String response = serviceClient.mybooks();
25 | logger.info("response: " + response);
26 | return response;
27 | }
28 |
29 | public String mybooksFallback() {
30 | return "mybooksFallback method called";
31 | }
32 |
33 | @HystrixCommand
34 | @RequestMapping("/test")
35 | public String test() {
36 | logger.info("test service called");
37 | return "book-service-client service is up";
38 | }
39 | }
--------------------------------------------------------------------------------
/book-service-client/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: book-service-client
4 | cloud:
5 | config:
6 | uri: http://localhost:8888
7 | ---
8 | spring:
9 | profiles: docker
10 | cloud:
11 | config:
12 | uri: http://config-server:8888
--------------------------------------------------------------------------------
/book-service-client/src/main/resources/logging.properties:
--------------------------------------------------------------------------------
1 | sun.net.www.protocol.http.HttpURLConnection.level=ALL
--------------------------------------------------------------------------------
/book-service/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | book-service
6 | book-service
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 | UTF-8
17 | 1.8
18 | app1_book-service
19 | v1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-eureka
26 |
27 |
28 | com.fasterxml.jackson.core
29 | jackson-databind
30 |
31 |
32 | org.springframework.cloud
33 | spring-cloud-starter-hystrix
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-web
38 |
39 |
40 | org.springframework.cloud
41 | spring-cloud-starter-sleuth
42 |
43 |
44 | org.springframework.cloud
45 | spring-cloud-sleuth-zipkin
46 |
47 |
48 | org.springframework.cloud
49 | spring-cloud-starter-config
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-starter-actuator
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.cloud
61 | spring-cloud-starter-parent
62 | Camden.SR5
63 | pom
64 | import
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | org.springframework.boot
73 | spring-boot-maven-plugin
74 |
75 |
76 | com.spotify
77 | docker-maven-plugin
78 | 0.4.13
79 |
80 | ${docker.image.name}:${docker.image.tag}
81 | src/main/docker
82 |
83 |
84 | /
85 | ${project.build.directory}
86 | ${project.build.finalName}.jar
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/book-service/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y netcat
3 | VOLUME /tmp
4 | ADD book-service-0.0.1-SNAPSHOT.jar app.jar
5 | RUN sh -c 'touch /app.jar'
6 | ADD run.sh run.sh
7 | RUN chmod +x run.sh
8 | CMD ./run.sh
9 |
10 |
--------------------------------------------------------------------------------
/book-service/src/main/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "********************************************************"
4 | echo "Waiting for the configuration server to start on port $CONFIGSERVER_PORT"
5 | echo "********************************************************"
6 | while ! `nc -z $CONFIGSERVER_HOST $CONFIGSERVER_PORT`; do sleep 3; done
7 | echo "******* Configuration Server has started"
8 |
9 | echo "********************************************************"
10 | echo "Starting sc-service "
11 | echo "********************************************************"
12 | java -Dspring.profiles.active=docker -jar app.jar
13 |
--------------------------------------------------------------------------------
/book-service/src/main/java/com/demoapp/bookservice/app/BookServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.bookservice.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix;
7 | import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.ComponentScan;
10 |
11 | @SpringBootApplication
12 | @EnableEurekaClient
13 | @EnableHystrix
14 | @ComponentScan(basePackages = "com.demoapp.bookservice.controller")
15 | public class BookServiceApplication {
16 |
17 | public static void main(String[] args) {
18 | SpringApplication.run(BookServiceApplication.class, args);
19 | }
20 |
21 | @Bean
22 | public AlwaysSampler defaultSampler() {
23 | return new AlwaysSampler();
24 | }
25 | }
--------------------------------------------------------------------------------
/book-service/src/main/java/com/demoapp/bookservice/controller/BookService.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.bookservice.controller;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
9 |
10 | @RestController
11 | public class BookService {
12 |
13 | private Logger logger = LoggerFactory.getLogger(BookService.class);
14 |
15 | @HystrixCommand
16 | @RequestMapping("/mybooks")
17 | public String ping() {
18 | logger.info("mybooks service called");
19 | return "your books: dan brawn - davinci";
20 | }
21 | }
--------------------------------------------------------------------------------
/book-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: book-service
4 | cloud:
5 | config:
6 | uri: http://localhost:8888
7 | ---
8 | spring:
9 | profiles: docker
10 | cloud:
11 | config:
12 | uri: http://config-server:8888
--------------------------------------------------------------------------------
/build_and_run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ./docker-clean.sh
3 |
4 | maven_clean_install_and_build_docker(){
5 | mvn clean install
6 | mvn docker:build
7 | }
8 |
9 | cd config-server
10 | maven_clean_install_and_build_docker
11 |
12 | cd ..
13 | cd discovery-server
14 | maven_clean_install_and_build_docker
15 |
16 | cd ..
17 | cd book-service
18 | maven_clean_install_and_build_docker
19 |
20 | cd ..
21 | cd book-service-client
22 | maven_clean_install_and_build_docker
23 |
24 | cd ..
25 | cd zipkin
26 | maven_clean_install_and_build_docker
27 |
28 | cd ..
29 | cd hystrix-dashboard
30 | maven_clean_install_and_build_docker
31 |
32 | cd ..
33 | cd zuul-proxy
34 | maven_clean_install_and_build_docker
35 |
36 | cd ..
37 | docker-compose up
38 |
--------------------------------------------------------------------------------
/config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | config-server
6 | config-server
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 |
17 | UTF-8
18 | 1.8
19 | app1_config-server
20 | v1
21 |
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-config-server
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.cloud
35 | spring-cloud-dependencies
36 | Camden.SR5
37 | pom
38 | import
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 | com.spotify
51 | docker-maven-plugin
52 | 0.4.13
53 |
54 | ${docker.image.name}:${docker.image.tag}
55 | src/main/docker
56 |
57 |
58 | /
59 | ${project.build.directory}
60 | ${project.build.finalName}.jar
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/config-server/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | VOLUME /tmp
3 | ADD config-server-0.0.1-SNAPSHOT.jar app.jar
4 | RUN sh -c 'touch /app.jar'
5 | ENV JAVA_OPTS=""
6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
--------------------------------------------------------------------------------
/config-server/src/main/java/com/demoapp/configserver/app/ConfigServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.configserver.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | @EnableConfigServer
8 | @SpringBootApplication
9 | public class ConfigServiceApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ConfigServiceApplication.class, args);
13 | }
14 | }
--------------------------------------------------------------------------------
/config-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8888
3 | spring:
4 | application:
5 | name: config-server
6 | profiles:
7 | active: native
8 | cloud:
9 | config:
10 | server:
11 | native:
12 | searchLocations: classpath:configs/
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | zipkin:
3 | baseUrl: http://localhost:9411/
4 | enabled: true
5 | eureka:
6 | instance:
7 | hostname: localhost
8 | client:
9 | service-url:
10 | _defaultZone: http://${eureka.instance.hostname}:8761/eureka/
11 | defaultZone: http://localhost:8761/eureka/
12 | healthcheck:
13 | enabled: true
14 | ---
15 | spring:
16 | profiles: docker
17 | zipkin:
18 | enabled: true
19 | baseUrl: http://zipkin:9411/
20 |
21 | eureka:
22 | instance:
23 | prefer-ip-address: true
24 | client:
25 | healthcheck:
26 | enabled: true
27 | service-url:
28 | defaultZone: http://discovery-server:8761/eureka/
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/book-service-client.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/book-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8083
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/hystrix-dashboard.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8082
3 |
4 | turbine:
5 | clusterNameExpression: new String("default")
6 | appConfig: SC-SERVICE ,SC-SERVICE-CLIENT
7 | combineHostPort: true
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/zipkin.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9411
--------------------------------------------------------------------------------
/config-server/src/main/resources/configs/zuul-proxy.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9999
3 |
4 | zuul:
5 | debug:
6 | request: true
--------------------------------------------------------------------------------
/discovery-server/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | discovery-server
6 | discovery-server
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 |
17 | UTF-8
18 | 1.8
19 | app1_discovery-server
20 | v1
21 |
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-starter-eureka-server
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-actuator
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-web
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-parent
43 | Camden.SR5
44 | pom
45 | import
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-maven-plugin
55 |
56 |
57 | com.spotify
58 | docker-maven-plugin
59 | 0.4.13
60 |
61 | ${docker.image.name}:${docker.image.tag}
62 | src/main/docker
63 |
64 |
65 | /
66 | ${project.build.directory}
67 | ${project.build.finalName}.jar
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/discovery-server/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | VOLUME /tmp
3 | ADD discovery-server-0.0.1-SNAPSHOT.jar app.jar
4 | RUN sh -c 'touch /app.jar'
5 | ENV JAVA_OPTS=""
6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
--------------------------------------------------------------------------------
/discovery-server/src/main/java/com/demoapp/discovery/app/DiscoveryServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.discovery.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaServer
9 | public class DiscoveryServerApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(DiscoveryServerApplication.class, args);
13 | }
14 | }
--------------------------------------------------------------------------------
/discovery-server/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8761
3 | eureka:
4 | client:
5 | register-with-eureka: false
6 | fetch-registry: false
7 | server:
8 | enableSelfPreservation: true
--------------------------------------------------------------------------------
/docker-clean.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | docker rm $(docker ps -a -q)
4 | docker rmi $(docker images -q)
5 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | config-server:
2 | image: app1_config-server:v1
3 | hostname: "config-server"
4 | ports:
5 | - "8888:8888"
6 |
7 | discovery-server:
8 | #build: .
9 | image: app1_discovery-server:v1
10 | hostname: "discovery-server"
11 | ports:
12 | - "8761:8761"
13 |
14 | zipkin:
15 | image: app1_zipkin:v1
16 | hostname: "zipkin"
17 | links:
18 | - "config-server:config-server"
19 | ports:
20 | - "9411:9411"
21 | environment:
22 | CONFIGSERVER_HOST: "config-server"
23 | CONFIGSERVER_PORT: "8888"
24 |
25 | book-service:
26 | image: app1_book-service:v1
27 | hostname: "book-service"
28 | links:
29 | - "config-server:config-server"
30 | - "discovery-server:discovery-server"
31 | - "zipkin:zipkin"
32 | ports:
33 | - "8083:8083"
34 | environment:
35 | CONFIGSERVER_HOST: "config-server"
36 | CONFIGSERVER_PORT: "8888"
37 |
38 | book-service-client:
39 | image: app1_book-service-client:v1
40 | hostname: "book-service-client"
41 | links:
42 | - "config-server:config-server"
43 | - "discovery-server:discovery-server"
44 | - "book-service:book-service"
45 | - "zipkin:zipkin"
46 | ports:
47 | - "8081:8081"
48 | environment:
49 | CONFIGSERVER_HOST: "config-server"
50 | CONFIGSERVER_PORT: "8888"
51 |
52 | hystrix-dashboard:
53 | image: app1_hystrix-dashboard:v1
54 | hostname: "hystrix-dashboard"
55 | links:
56 | - "config-server:config-server"
57 | - "discovery-server:discovery-server"
58 | - "book-service-client:book-service-client"
59 | - "book-service:book-service"
60 | - "zuul-proxy:zuul-proxy"
61 | ports:
62 | - "8082:8082"
63 | environment:
64 | CONFIGSERVER_HOST: "config-server"
65 | CONFIGSERVER_PORT: "8888"
66 |
67 | zuul-proxy:
68 | image: app1_zuul-proxy:v1
69 | hostname: "zuul-proxy"
70 | links:
71 | - "config-server:config-server"
72 | - "discovery-server:discovery-server"
73 | - "book-service-client:serviceclient"
74 | - "book-service:book-service"
75 | - "zipkin:zipkin"
76 | ports:
77 | - "9999:9999"
78 | environment:
79 | CONFIGSERVER_HOST: "config-server"
80 | CONFIGSERVER_PORT: "8888"
81 |
--------------------------------------------------------------------------------
/etc/architecture.odg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yusuf-daglioglu/spring_microservices_demo/3c7bd89edf2889c59bb59d31c015bca937cfa81d/etc/architecture.odg
--------------------------------------------------------------------------------
/etc/architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yusuf-daglioglu/spring_microservices_demo/3c7bd89edf2889c59bb59d31c015bca937cfa81d/etc/architecture.png
--------------------------------------------------------------------------------
/hystrix-dashboard/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | hystrix-dashboard
6 | hystrix-dashboard
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 |
17 | UTF-8
18 | 1.8
19 | app1_hystrix-dashboard
20 | v1
21 |
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-starter-hystrix-dashboard
27 |
28 |
29 | org.springframework.cloud
30 | spring-cloud-starter-turbine
31 |
32 |
33 | javax.servlet
34 | servlet-api
35 |
36 |
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-config
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-actuator
45 |
46 |
47 |
48 |
49 |
50 |
51 | org.springframework.cloud
52 | spring-cloud-dependencies
53 | Camden.SR5
54 | pom
55 | import
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 | com.spotify
68 | docker-maven-plugin
69 | 0.4.13
70 |
71 | ${docker.image.name}:${docker.image.tag}
72 | src/main/docker
73 |
74 |
75 | /
76 | ${project.build.directory}
77 | ${project.build.finalName}.jar
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/hystrix-dashboard/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y netcat
3 | VOLUME /tmp
4 | ADD hystrix-dashboard-0.0.1-SNAPSHOT.jar app.jar
5 | RUN sh -c 'touch /app.jar'
6 | ADD run.sh run.sh
7 | RUN chmod +x run.sh
8 | CMD ./run.sh
9 |
--------------------------------------------------------------------------------
/hystrix-dashboard/src/main/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 |
4 |
5 | echo "********************************************************"
6 | echo "Waiting for the configuration server to start on port $CONFIGSERVER_PORT"
7 | echo "********************************************************"
8 | while ! `nc -z $CONFIGSERVER_HOST $CONFIGSERVER_PORT`; do sleep 3; done
9 | echo "******* Configuration Server has started"
10 |
11 |
12 |
13 | echo "********************************************************"
14 | echo "Starting sc-hystrix-dashboard "
15 | echo "********************************************************"
16 | java -Dspring.profiles.active=docker -jar app.jar
17 |
--------------------------------------------------------------------------------
/hystrix-dashboard/src/main/java/com/demoapp/hystrixdashboard/app/HystrixDashboardApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.hystrixdashboard.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
7 | import org.springframework.cloud.netflix.turbine.EnableTurbine;
8 |
9 | @SpringBootApplication
10 | @EnableHystrixDashboard
11 | @EnableTurbine
12 | @EnableDiscoveryClient
13 | public class HystrixDashboardApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(HystrixDashboardApplication.class, args);
17 | }
18 | }
--------------------------------------------------------------------------------
/hystrix-dashboard/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: hystrix-dashboard
4 | cloud:
5 | config:
6 | uri: http://localhost:8888
7 | ---
8 | spring:
9 | profiles: docker
10 | cloud:
11 | config:
12 | uri: http://config-server:8888
13 |
--------------------------------------------------------------------------------
/start-only-config-server.sh:
--------------------------------------------------------------------------------
1 | cd config-server
2 | mvn package docker:build -DskipTests
3 | cd..
4 | docker-compose up -d config-server
5 | docker-compose logs
6 |
7 | # to close it:
8 | # docker ps
9 | # docker stop *id_of_config_server_from_ps_command*
10 |
11 | # config server test url to return book-service's configs
12 | # http://localhost:8888/book-service/default
13 |
--------------------------------------------------------------------------------
/zipkin/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | zipkin
6 | zipkin
7 | 0.0.1-SNAPSHOT
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.4.RELEASE
13 |
14 |
15 |
16 |
17 | UTF-8
18 | 1.8
19 | app1_zipkin
20 | v1
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter
27 |
28 |
29 | io.zipkin.java
30 | zipkin-server
31 |
32 |
33 | org.springframework.cloud
34 | spring-cloud-starter-config
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-actuator
39 |
40 |
41 | io.zipkin.java
42 | zipkin-autoconfigure-ui
43 | runtime
44 |
45 |
46 |
47 |
48 |
49 |
50 | org.springframework.cloud
51 | spring-cloud-dependencies
52 | Camden.SR5
53 | pom
54 | import
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | org.springframework.boot
63 | spring-boot-maven-plugin
64 |
65 |
66 | com.spotify
67 | docker-maven-plugin
68 | 0.4.13
69 |
70 | ${docker.image.name}:${docker.image.tag}
71 | src/main/docker
72 |
73 |
74 | /
75 | ${project.build.directory}
76 | ${project.build.finalName}.jar
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/zipkin/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y netcat
3 | VOLUME /tmp
4 | ADD zipkin-0.0.1-SNAPSHOT.jar app.jar
5 | RUN sh -c 'touch /app.jar'
6 | ADD run.sh run.sh
7 | RUN chmod +x run.sh
8 | CMD ./run.sh
9 |
10 |
--------------------------------------------------------------------------------
/zipkin/src/main/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "********************************************************"
4 | echo "Waiting for the configuration server to start on port $CONFIGSERVER_PORT"
5 | echo "********************************************************"
6 | while ! `nc -z $CONFIGSERVER_HOST $CONFIGSERVER_PORT`; do sleep 3; done
7 | echo "******* Configuration Server has started"
8 |
9 | echo "********************************************************"
10 | echo "Starting zipking "
11 | echo "********************************************************"
12 | java -Dspring.profiles.active=docker -jar app.jar
13 |
--------------------------------------------------------------------------------
/zipkin/src/main/java/com/demoapp/zipkin/app/ZipkinApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.zipkin.app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import zipkin.server.EnableZipkinServer;
7 |
8 | @SpringBootApplication
9 | @EnableZipkinServer
10 | public class ZipkinApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(ZipkinApplication.class, args);
14 | }
15 | }
--------------------------------------------------------------------------------
/zipkin/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: zipkin
4 | cloud:
5 | config:
6 | uri: http://localhost:8888
7 | ---
8 | spring:
9 | profiles: docker
10 | cloud:
11 | config:
12 | uri: http://config-server:8888
--------------------------------------------------------------------------------
/zuul-proxy/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | zuul-proxy
5 | zuul-proxy
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | org.springframework.boot
10 | spring-boot-starter-parent
11 | 1.4.4.RELEASE
12 |
13 |
14 |
15 |
16 | UTF-8
17 | 1.8
18 | app1_zuul-proxy
19 | v1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-zuul
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-starter-security
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-security
34 |
35 |
36 |
37 | org.springframework.cloud
38 | spring-cloud-starter-feign
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-eureka
43 |
44 |
45 | com.fasterxml.jackson.core
46 | jackson-databind
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-web
51 |
52 |
53 | org.springframework.cloud
54 | spring-cloud-starter-sleuth
55 |
56 |
57 | org.springframework.cloud
58 | spring-cloud-sleuth-zipkin
59 |
60 |
61 | org.springframework.cloud
62 | spring-cloud-starter-config
63 |
64 |
65 | org.springframework.boot
66 | spring-boot-starter-actuator
67 |
68 |
69 | org.springframework.cloud
70 | spring-cloud-starter-hystrix
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.springframework.cloud
78 | spring-cloud-starter-parent
79 | Camden.SR5
80 | pom
81 | import
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | org.springframework.boot
90 | spring-boot-maven-plugin
91 |
92 |
93 | com.spotify
94 | docker-maven-plugin
95 | 0.4.13
96 |
97 | ${docker.image.name}:${docker.image.tag}
98 | src/main/docker
99 |
100 |
101 | /
102 | ${project.build.directory}
103 | ${project.build.finalName}.jar
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/zuul-proxy/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk:8-jre
2 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y netcat
3 | VOLUME /tmp
4 | ADD zuul-proxy-0.0.1-SNAPSHOT.jar app.jar
5 | RUN sh -c 'touch /app.jar'
6 | ADD run.sh run.sh
7 | RUN chmod +x run.sh
8 | CMD ./run.sh
9 |
10 |
--------------------------------------------------------------------------------
/zuul-proxy/src/main/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "********************************************************"
4 | echo "Waiting for the configuration server to start on port $CONFIGSERVER_PORT"
5 | echo "********************************************************"
6 | while ! `nc -z $CONFIGSERVER_HOST $CONFIGSERVER_PORT`; do sleep 3; done
7 | echo "******* Configuration Server has started"
8 |
9 | echo "********************************************************"
10 | echo "Starting zuul-proxy "
11 | echo "********************************************************"
12 | java -Dspring.profiles.active=docker -jar app.jar
13 |
--------------------------------------------------------------------------------
/zuul-proxy/src/main/java/com/demoapp/zuulproxy/app/ZuulProxyApplication.java:
--------------------------------------------------------------------------------
1 | package com.demoapp.zuulproxy.app;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.autoconfigure.security.SecurityProperties;
7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
9 | import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.context.annotation.Configuration;
12 | import org.springframework.core.annotation.Order;
13 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
14 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
15 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
16 |
17 | @EnableZuulProxy
18 | @SpringBootApplication
19 | @EnableDiscoveryClient
20 | public class ZuulProxyApplication {
21 |
22 | public static void main(String[] args) {
23 | SpringApplication.run(ZuulProxyApplication.class, args);
24 | }
25 |
26 | @Bean
27 | public AlwaysSampler defaultSampler() {
28 | return new AlwaysSampler();
29 | }
30 |
31 | @Autowired
32 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
33 | auth.inMemoryAuthentication().withUser("user").password("pass").roles("ADMIN");
34 | }
35 |
36 | @Configuration
37 | @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
38 | protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
39 | @Override
40 | protected void configure(HttpSecurity http) throws Exception {
41 | http.httpBasic().and().authorizeRequests().anyRequest().authenticated();
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/zuul-proxy/src/main/java/com/demoapp/zuulproxy/proxy/AccessLogFilter.java:
--------------------------------------------------------------------------------
1 | package com.etereration.sc.zuul.proxy;
2 |
3 | import java.util.List;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpServletResponse;
7 |
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.stereotype.Component;
11 |
12 | import com.netflix.zuul.ZuulFilter;
13 | import com.netflix.zuul.context.RequestContext;
14 |
15 |
16 | @Component
17 | public class AccessLogFilter extends ZuulFilter {
18 |
19 | Logger logger = LoggerFactory.getLogger(AccessLogFilter.class);
20 |
21 | @Override
22 | public String filterType() {
23 | return "post";
24 | }
25 |
26 | @Override
27 | public int filterOrder() {
28 | return 0;
29 | }
30 |
31 | @Override
32 | public boolean shouldFilter() {
33 | return true;
34 | }
35 |
36 | @Override
37 | public Object run() {
38 | HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
39 | HttpServletResponse response = RequestContext.getCurrentContext().getResponse();
40 |
41 | logger.info("REQUEST :: < " + request.getScheme() + " " + request.getLocalAddr() + ":" + request.getLocalPort());
42 | logger.info("REQUEST :: < " + request.getMethod() + " " + request.getRequestURI() + " " + request.getProtocol());
43 | logger.info("RESPONSE:: > HTTP:" + response.getStatus());
44 | @SuppressWarnings("unchecked") final List routingDebug = (List) RequestContext.getCurrentContext().get("routingDebug");
45 | routingDebug.forEach(logger::info);
46 | return null;
47 | }
48 | }
--------------------------------------------------------------------------------
/zuul-proxy/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: zuul-proxy
4 | cloud:
5 | config:
6 | uri: http://localhost:8888
7 | ---
8 | spring:
9 | profiles: docker
10 | cloud:
11 | config:
12 | uri: http://config-server:8888
--------------------------------------------------------------------------------