Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ Goals: -
6. Spring Hysterix circuit breaker - support added
7. Spring Hysterix Dashboard - deployed as a docker container
8. Spring ZuulProxy- deployed as a docker container
9. Spring Turbine - deployed as a docker container - works only in none docker envwith http push, it needs additional work as in docker it requires AMQP
9. Spring Turbine - deployed as a docker container
10. mysql - deployed as docker container and populated via script on start up
11. Spring sleuth and Zipkin
11. Spring sleuth and Zipkin - deployed as a docker container
Stretch Goals --
12. ELK stack
13. Distributed caching
14. Stretch Goal - Async API aggregator written in RxJava
15. Stretch Goal - Jenkins
14. Async API aggregator written in RxJava
15. Jenkins
16. Angular 4 based UI to got with the microservices

<div>
I have written <b>install.sh</b> which does the job of CI of building and packaging the Spring boot application and put them in a directory
from where they can be mounted to docker volumes.
</div>

<b>install.sh</b> will also take care of bringing all containers using docker-compose.
So clone the project, create a volume directory in your system and modify the install.sh and docker-compose.yml accordingly. Finally run .install.sh.
TODO - modify the install.sh so that it creates the working directory
So clone the project, create a volume directory in your system and modify the install.sh and docker-compose.yml accordingly. Finally run
<code> sudo .install.sh.</code>


Under the hood this is what happens -
1. Builds all microservices, eureka server, config
Expand All @@ -35,7 +38,12 @@ Under the hood this is what happens -
4. Bring up config server
5. Bring up Eureka Server
6. Bring up microservices - Eureka clients.
7. Add them into one network so that they can communicate
7. Enable Sleuth on microservices
8. Configure microservices so that they send the trace to Spring AMQP
9. Use Spring cloud Zipkin to read the trace from AMQP for timing information
10. Use the trace from AMQP for monitoring in Turbine
11. Add them into one network so that they can communicate
12. Ohh, btw, the Config are externalized using Spring cloud config and are situated at https://github.com/hiteshjoshi1/microservice-docker-cart-config.git

Working Endpoints so far :-
<div>
Expand All @@ -46,7 +54,13 @@ Working Endpoints so far :-
<li>Invoice - http://localhost:4444/invoice</li>
<li>Config - http://localhost:5555/customer-service/dev</li>
<li>Hystrix Monitor - http://localhost:7777/hystrix</li>
<li>Endpoint with a Circuit breaker and fallback - http://localhost:2222/customers/1/orders</li>
<li>Zipkin UI - http://localhost:9411/zipkin/<li>
<li>Example of an endpoint with a Circuit breaker and fallback(GET) - http://localhost:2222/customers/1/orders</li>
<li>POST with Hytrix circuit breaker

curl -H "Content-Type: application/json" -X POST -d '{"customerId":1,"modePayId":2,"cashierName":"Rambo","items":[{"itemId":1,"quantity":100,"unitCost":10}]}' http://localhost:2222/customers/order

</li>
</ul>
</div>

Expand All @@ -59,18 +73,26 @@ Zuul Routes example - You can add Filters on the Zuul Proxy layer. This examples
<li> </li>


Docker config - http://localhost:5555/customer-service/docker <br>

Hystrix Monitor - We need to provide the application that needs to be montored. <br>
Please input - http://localhost:2222/hystrix.stream<br>
If you are in docker - input http://172.20.0.7:2222/hystrix.stream <br>
Please input in local - http://localhost:2222/hystrix.stream<br>
If you are using docker - input http://172.20.0.7:2222/hystrix.stream <br>
Final URL should looks like this - http://localhost:7777/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A2222%2Fhystrix.stream&title=Customer-Hystrix


For turbine based monitoring - <BR>
http://localhost:7777/turbine.stream?cluster=CUSTOMER-SERVICE <br>
In docker->
http://monitor:7777/turbine.stream?cluster=CUSTOMER-SERVICE <br>

Final URL should looks like this - http://localhost:7777/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A2222%2Fhystrix.stream&title=Customer-Hystrix

Note-

Spring cloud turbine and Spring cloud zipkin can work over http. But this configuration does not work in a cloud deployement/docker.
For it to work you need to use a messaging service such as kafka or Rabbit AMQP.

for turbine based monitoring
http://172.20.0.7:7777/turbine.stream?cluster=CUSTOMER-SERVICE
I have done installation of Erlang and RabbitMq in my local(windows) and spring connects to it without a hitch.
However in order to run it in a docker based enviornment, you have to explicitly provide connection properties in the application properties.

-------------------------------------------------------------------------------------------------------------

Expand Down
29 changes: 23 additions & 6 deletions customer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
Expand Down Expand Up @@ -79,11 +75,32 @@
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<!-- zipkin and sleuth -->
<!-- zipkin and sleuth for amqp, for direct use of hhtp with zipkin use different zipkin dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-stream</artifactId>
</dependency>

<!-- Hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<!-- Using Hystrix Stream -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<!-- Using Rabbit AMQP -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ RestTemplate restTemplate() {
return new RestTemplate();
}

@Bean
public AlwaysSampler defaultSampler() {
return new AlwaysSampler();
}
}
20 changes: 15 additions & 5 deletions customer/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ spring:
banner-mode: "off"
freemarker:
enabled: false # Ignore Eureka dashboard FreeMarker templates
zipkin:
base-url: http://localhost:9411/

sleuth:
sampler:
percentage: 1.0


server:
port: ${customer.port}



feign:
hystrix: # even if eclipse is complaining, this is required
enabled: true
Expand Down Expand Up @@ -45,13 +51,17 @@ spring:
datasource:
url: jdbc:mysql://localhost:3306/microservices_cust
username: root
password: test

password: test
rabbitmq:
host: rabbitmq
port: 5672
username: guest
password: guest

eureka:
client:
serviceUrl:
defaultZone: http://eureka:${customer.discovery.port}/eureka/ # using eureka instead of localhost
instance:
leaseRenewalIntervalInSeconds: 5 # DO NOT DO THIS IN PRODUCTION
preferIpAddress: true
preferIpAddress: true
48 changes: 34 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ services:
- ./init_schema:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: test


rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
hostname: rabbitmq
restart: always
ports:
- "15672:15672"
- "5672:5672"
networks:
- microservicesnet
logging:
options:
max-size: "10m"
max-file: "10"
eureka:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: eureka
Expand Down Expand Up @@ -58,40 +72,45 @@ services:
condition: service_started
config:
condition: service_healthy
invoice1:
condition: service_started
rabbitmq:
condition: service_started

inventory1:
invoice1:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: inventory1
container_name: invoice1
ports:
- "3333:3333"
- "4444:4444"
networks:
- microservicesnet
volumes:
- /home/hitesh/jarloc:/data
command: -jar -Dspring.profiles.active=docker -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod -Dspring.datasource.password=test /data/inventory-0.0.1-SNAPSHOT.jar
command: -jar -Dspring.profiles.active=docker -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_invoice -Dspring.datasource.password=test /data/invoice-0.0.1-SNAPSHOT.jar
depends_on:
db:
condition: service_started
config:
condition: service_healthy
rabbitmq:
condition: service_started

invoice1:
inventory1:
image: hiteshjoshi1/microservice-docker-cart-example
container_name: invoice1
container_name: inventory1
ports:
- "4444:4444"
- "3333:3333"
networks:
- microservicesnet
volumes:
- /home/hitesh/jarloc:/data
command: -jar -Dspring.profiles.active=docker -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_invoice -Dspring.datasource.password=test /data/invoice-0.0.1-SNAPSHOT.jar
command: -jar -Dspring.profiles.active=docker -Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod -Dspring.datasource.password=test /data/inventory-0.0.1-SNAPSHOT.jar
depends_on:
db:
condition: service_started
config:
condition: service_healthy
rabbitmq:
condition: service_started


monitor:
image: hiteshjoshi1/microservice-docker-cart-example
Expand All @@ -108,8 +127,8 @@ services:
condition: service_started
config:
condition: service_healthy
customer1:
condition: service_started
rabbitmq:
condition: service_started

zuul:
image: hiteshjoshi1/microservice-docker-cart-example
Expand Down Expand Up @@ -137,7 +156,8 @@ services:
depends_on:
config:
condition: service_healthy

rabbitmq:
condition: service_started


networks:
Expand Down
32 changes: 21 additions & 11 deletions inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand All @@ -74,10 +65,29 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- zipkin and sleuth -->
<!-- zipkin and sleuth for amqp, for direct use of hhtp with zipkin use different zipkin dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-stream</artifactId>
</dependency>
<!-- Hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<!-- Using Hystrix Stream -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<!-- Using Rabbit AMQP -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>

</dependencies>
Expand Down
8 changes: 7 additions & 1 deletion inventory/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ spring:
jpa:
hibernate:
ddl-auto: none
rabbitmq:
host: rabbitmq
port: 5672
username: guest
password: guest


eureka:
client:
serviceUrl:
defaultZone: http://eureka:${inventory.discovery.port}/eureka/ # using eureka instead of localhost


Loading