Tutorials for learning Spring Cloud. Each example shows the basic usage of one component of Spring Cloud. See also shuaicj/spring-cloud-example for a complete demo.
$ mvn clean package
-
tt01-config-native - Configuration with native mode of Spring Cloud Config
- Run
$ java -jar tt01*/*server/target/*.jar$ java -jar tt01*/*client/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould printport: 8080, message: Hello, I'm tt01.
- Run
-
tt02-config-git - Configuration with git mode of Spring Cloud Config
- Run
$ java -jar tt02*/*server/target/*.jar$ java -jar tt02*/*client/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould printport: 8080, message: Hello, I'm tt02.
- Run
-
tt03-config-zookeeper - Configuration with Spring Cloud Zookeeper
- Install and start Zookeeper. If using Homebrew on Mac:
$ brew install zookeeper$ zkServer start
Now a local zookeeper is running at
localhost:2181. - Create configurations in zookeeper:
$ zkClizk$ create /config ''zk$ create /config/tt03-hello ''zk$ create /config/tt03-hello/server ''zk$ create /config/tt03-hello/server/port 8080zk$ create /config/tt03-hello/hello ''zk$ create /config/tt03-hello/hello/message "Hello, I'm tt03."
- Run
$ java -jar tt03*/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould printport: 8080, message: Hello, I'm tt03.
- Install and start Zookeeper. If using Homebrew on Mac:
-
tt04-config-consul - Configuration with Spring Cloud Consul
- Install and start Consul. If using Homebrew on Mac:
$ brew install consul$ consul agent -dev -advertise 127.0.0.1
Now a consul agent is running at
localhost:8500. - Create configurations in consul:
$ consul kv put config/tt04-hello/server/port 8080$ consul kv put config/tt04-hello/hello/message "Hello, I'm tt04."
- Run
$ java -jar tt04*/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould printport: 8080, message: Hello, I'm tt04.
- Install and start Consul. If using Homebrew on Mac:
-
tt11-eureka-standalone - Standalone mode of Spring Cloud Netflix Eureka
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt11*/*client/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould print out instance info.- Open
http://localhost:8761in browser to check eureka portal. - Open
http://localhost:8761/eureka/appsin browser to check registered services.
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt12-eureka-ha - HA mode of Spring Cloud Netflix Eureka
- Run
$ java -jar tt12*/*server/target/*.jar --spring.profiles.active=peer1$ java -jar tt12*/*server/target/*.jar --spring.profiles.active=peer2$ java -jar tt12*/*client/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould print out instance info.- Open
http://localhost:8761orhttp://localhost:8762in browser to check eureka portal. - Open
http://localhost:8761/eureka/appsin browser to check registered services.
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt13-eureka-config - Register config server to Spring Cloud Netflix Eureka
- Run
$ java -jar tt13*/*eureka-server/target/*.jar$ java -jar tt13*/*config-server/target/*.jar$ java -jar tt13*/*config-client/target/*.jar
- Verify
$ curl http://localhost:8080/helloshould printport: 8080, message: Hello, I'm tt13.
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt21-hystrix - Simple usage of Spring Cloud Netflix Hystrix
- Run
$ java -jar tt21*/target/*.jar
- Verify
$ curl http://localhost:8080/hello?name=abcshould printHello ABC!.$ curl http://localhost:8080/hello?name=ashould printHello A [FALLBACK]!.
- Run
-
tt22-hystrix-timeout - Timeout of Spring Cloud Netflix Hystrix
- Run
$ java -jar tt22*/*api/target/*.jar$ java -jar tt22*/*consumer/target/*.jar
- Verify
- Repeat the following
curlandCONSUMER [FALLBACK]should be printed out randomly.$ curl http://localhost:8081/consume
- Repeat the following
- Run
-
tt23-hystrix-dashboard - Dashboard of Spring Cloud Netflix Hystrix
- Run
$ java -jar tt23*/*server/target/*.jar$ java -jar tt23*/*client/target/*.jar
- Verify
- Open
http://localhost:8081/hystrixin browser and you will see the dashboard. Inputhttp://localhost:8080/hystrix.streamand clickMonitor Streambutton. - Do the following two
curlrandomly and watch the changes on dashboard.$ curl http://localhost:8080/hello?name=abc$ curl http://localhost:8080/hello?name=a
- Open
- Run
-
tt31-ribbon-resttemplate - RestTemplate and Spring Cloud Netflix Ribbon
- Run
$ java -jar tt31*/*api/target/*.jar --server.port=8081 --hello.id=server-1$ java -jar tt31*/*api/target/*.jar --server.port=8082 --hello.id=server-2$ java -jar tt31*/*consumer/target/*.jar
- Verify
- Repeat the following
curlandserver-1,server-2should say hello by turns.$ curl http://localhost:8080/consume
- Repeat the following
- Run
-
tt32-ribbon-eureka - Spring Cloud Netflix Ribbon with Eureka
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt32*/*api/target/*.jar --server.port=8081 --hello.id=server-1$ java -jar tt32*/*api/target/*.jar --server.port=8082 --hello.id=server-2$ java -jar tt32*/*consumer/target/*.jar
- Verify
- Repeat the following
curlandserver-1,server-2should say hello by turns.$ curl http://localhost:8080/consume
- Repeat the following
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt41-feign - Simple usage of Spring Cloud Netflix Feign
- Run
$ java -jar tt41*/*api/target/*.jar --server.port=8081 --hello.id=server-1$ java -jar tt41*/*api/target/*.jar --server.port=8082 --hello.id=server-2$ java -jar tt41*/*consumer/target/*.jar
- Verify
- Repeat the following
curlandserver-1,server-2should say hello by turns.$ curl http://localhost:8080/consume
- Repeat the following
- Run
-
tt42-feign-hystrix-eureka - Spring Cloud Netflix Feign with Hystrix, Eureka
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt42*/*api/target/*.jar --server.port=8081 --hello.id=server-1$ java -jar tt42*/*api/target/*.jar --server.port=8082 --hello.id=server-2$ java -jar tt42*/*consumer/target/*.jar
- Verify
- Repeat the following
curland hystrix fallback should be triggered randomly.$ curl http://localhost:8080/consume
- Repeat the following
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt51-turbine - Simple usage of Spring Cloud Netflix Turbine
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt51*/*api-1/target/*.jar --server.port=8081 --hello.id=server-1-1$ java -jar tt51*/*api-1/target/*.jar --server.port=8082 --hello.id=server-1-2$ java -jar tt51*/*api-2/target/*.jar --server.port=8083 --hello.id=server-2-1$ java -jar tt51*/*api-2/target/*.jar --server.port=8084 --hello.id=server-2-2$ java -jar tt51*/*server/target/*.jar$ java -jar tt23*/*server/target/*.jar --server.port=9090
- Verify
- Open
http://localhost:9090/hystrixin browser and you will see the dashboard. Inputhttp://localhost:8080/turbine.streamand clickMonitor Streambutton. - Do the following two
curlrandomly and watch the changes on dashboard.$ curl http://localhost:8081/consume$ curl http://localhost:8082/consume$ curl http://localhost:8083/consume$ curl http://localhost:8084/consume
- Open
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt52-turbine-rabbitmq - Spring Cloud Netflix Turbine with RabbitMQ
- Install and start RabbitMQ. If using Homebrew on Mac:
$ brew install rabbitmq$ rabbitmq-server
Now you can check if rabbitmq is running in browser
http://localhost:15672. - Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt52*/*api-1/target/*.jar --server.port=8081 --hello.id=server-1-1$ java -jar tt52*/*api-1/target/*.jar --server.port=8082 --hello.id=server-1-2$ java -jar tt52*/*api-2/target/*.jar --server.port=8083 --hello.id=server-2-1$ java -jar tt52*/*api-2/target/*.jar --server.port=8084 --hello.id=server-2-2$ java -jar tt52*/*server/target/*.jar$ java -jar tt23*/*server/target/*.jar --server.port=9090
- Verify
- Same as
tt51-turbine
- Same as
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Install and start RabbitMQ. If using Homebrew on Mac:
-
tt61-zuul - Simple usage of Spring Cloud Netflix Zuul
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt61*/*api-1/target/*.jar --server.port=8081 --hello.id=server-1-1$ java -jar tt61*/*api-1/target/*.jar --server.port=8082 --hello.id=server-1-2$ java -jar tt61*/*api-2/target/*.jar --server.port=8083 --hello.id=server-2-1$ java -jar tt61*/*api-2/target/*.jar --server.port=8084 --hello.id=server-2-2$ java -jar tt61*/*server/target/*.jar
- Verify
- Repeat the following
curland each service instance should say hello by turns.$ curl http://localhost:8080/tt61-api-1/hello$ curl http://localhost:8080/tt61-api-2/hello
- Repeat the following
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt62-zuul-route - Customize routes of Spring Cloud Netflix Zuul
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt61*/*api-1/target/*.jar --server.port=8081 --hello.id=server-1-1$ java -jar tt61*/*api-1/target/*.jar --server.port=8082 --hello.id=server-1-2$ java -jar tt61*/*api-2/target/*.jar --server.port=8083 --hello.id=server-2-1$ java -jar tt61*/*api-2/target/*.jar --server.port=8084 --hello.id=server-2-2$ java -jar tt62*/target/*.jar
- Verify
- Repeat the following
curland each service instance should say hello by turns.$ curl http://localhost:8080/api1/hello$ curl http://localhost:8080/api2/hello
- Repeat the following
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt71-sleuth - Simple usage of Spring Cloud Sleuth
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt71*/*api-1/target/*.jar$ java -jar tt71*/*api-2/target/*.jar$ java -jar tt71*/*api-3/target/*.jar
- Verify
$ curl http://localhost:8081/hello?name=user- and you shoud see some log text like
which means
[tt71-api-1,aff79919529ce79f,4a8442d5d47112ba,false]See doc for more details.[appname,traceId,spanId,exportable]
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt72-sleuth-feign - Spring Cloud Sleuth with Feign
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt72*/*api-1/target/*.jar$ java -jar tt72*/*api-2/target/*.jar$ java -jar tt72*/*api-3/target/*.jar
- Verify
- Same as
tt71-sleuth
- Same as
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt73-sleuth-zipkin - Spring Cloud Sleuth with Zipkin
- Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt73*/*server/target/*.jar$ java -jar tt73*/*api-1/target/*.jar$ java -jar tt73*/*api-2/target/*.jar$ java -jar tt73*/*api-3/target/*.jar
- Verify
- Repeat
$ curl http://localhost:8081/hello?name=userfor several times. - Open
http://localhost:9411in browser and you should seett73-api-1or the other two.- Click
Find Tracesto check the service duration details. - Click
Dependenciesyou should seett73-api-1 => tt73-api-2 => tt73-api-3
- Click
- Repeat
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Run
-
tt74-sleuth-zipkin-rabbitmq - Spring Cloud Sleuth with Zipkin, RabbitMQ
- Install and start RabbitMQ. If using Homebrew on Mac:
$ brew install rabbitmq$ rabbitmq-server
Now you can check if rabbitmq is running in browser
http://localhost:15672. - Run
$ java -jar tt11*/*server/target/*.jar$ java -jar tt74*/*server/target/*.jar$ java -jar tt74*/*api-1/target/*.jar$ java -jar tt74*/*api-2/target/*.jar$ java -jar tt74*/*api-3/target/*.jar
- Verify
- Same as
tt73-sleuth-zipkin
- Same as
It takes one or two minutes for Eureka to take effect. You should wait this time to do the verify.
- Install and start RabbitMQ. If using Homebrew on Mac: