├── sample-config
├── src
│ └── main
│ │ ├── resources
│ │ ├── config
│ │ │ └── sample-service.yml
│ │ ├── bootstrap.yml
│ │ └── application.yml
│ │ └── java
│ │ └── sample
│ │ └── config
│ │ └── ConfigServerApplication.java
└── pom.xml
├── .gitignore
├── sample-service
├── src
│ └── main
│ │ ├── resources
│ │ ├── bootstrap.yml
│ │ └── application.yml
│ │ └── java
│ │ └── sample
│ │ └── service
│ │ ├── Application.java
│ │ └── SamplePropController.java
└── pom.xml
├── README.adoc
└── pom.xml
/sample-config/src/main/resources/config/sample-service.yml:
--------------------------------------------------------------------------------
1 | ---
2 | service:
3 | prop: Prop value from Config server
--------------------------------------------------------------------------------
/sample-config/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | ---
2 | spring:
3 | application:
4 | name: sample-config
5 | profiles:
6 | active: native
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .settings/
3 | .springBeans
4 | .classpath
5 | .project
6 | bin/
7 | .cache
8 | .gradle
9 | .idea
10 | build/
11 | out/
12 | *.ipr
13 | *.iws
14 | *.iml
15 |
--------------------------------------------------------------------------------
/sample-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | ---
2 | spring:
3 | application:
4 | name: sample-service
5 | cloud:
6 | config:
7 | enabled: true
8 | uri: ${configserver.url:http://localhost:8888}
9 |
--------------------------------------------------------------------------------
/sample-config/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | ---
2 | spring:
3 | cloud:
4 | config:
5 | server:
6 | native:
7 | searchLocations: classpath:/config
8 |
9 | server:
10 | port: 8888
11 |
--------------------------------------------------------------------------------
/sample-service/src/main/java/sample/service/Application.java:
--------------------------------------------------------------------------------
1 | package sample.service;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 |
7 | @SpringBootApplication
8 | public class Application {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(Application.class, args);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/sample-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | ---
2 | server:
3 | port: 8080
4 |
5 | samplepong:
6 | ribbon:
7 | DeploymentContextBasedVipAddresses: sample-pong
8 | ReadTimeout: 5000
9 | MaxAutoRetries: 2
10 |
11 | samplepongdirect:
12 | ribbon:
13 | DeploymentContextBasedVipAddresses: sample-pong
14 | listOfServers: localhost:8082
15 | ReadTimeout: 5000
16 | MaxAutoRetries: 2
17 |
18 | another:
19 | key: anotherkeyvalue
20 |
--------------------------------------------------------------------------------
/sample-config/src/main/java/sample/config/ConfigServerApplication.java:
--------------------------------------------------------------------------------
1 | package sample.config;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | @SpringBootApplication
8 | @EnableConfigServer
9 | public class ConfigServerApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ConfigServerApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/sample-service/src/main/java/sample/service/SamplePropController.java:
--------------------------------------------------------------------------------
1 | package sample.service;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.cloud.context.config.annotation.RefreshScope;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @RestController
9 | @RefreshScope
10 | public class SamplePropController {
11 |
12 | @Value("${service.prop:notset}")
13 | private String aRefreshableProperty;
14 |
15 | @RequestMapping("/show")
16 | public String sendMessage() {
17 | return this.aRefreshableProperty;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | Spring Cloud Bus Demo
2 | ---------------------
3 |
4 | This is a simple demonstration of Spring Cloud Bus feature of being able to refresh properties in all instances of an application
5 |
6 | .Start up RabbitMQ Server
7 | [source,java]
8 | ----
9 | rabbitmq-server
10 | ----
11 |
12 | .Start up Config Server
13 | [source,java]
14 | ----
15 | cd sample-config
16 | mvn spring-boot:run
17 | ----
18 |
19 | .Start up Service instance 1
20 | [source,java]
21 | ----
22 | cd sample-service
23 | mvn spring-boot:run
24 | ----
25 |
26 | .Start up Service instance 2
27 | [source,java]
28 | ----
29 | cd sample-service
30 | mvn spring-boot:run -Dserver.port=8081
31 | ----
32 |
33 | If all the applications have come up cleanly, the endpoint should be available at http://localhost:8080/show, http://localhost:8081/show
34 |
35 |
36 | . To change the property, open sample-config/src/main/resources/config/sample-service.yml and modify `service.prop` value and restart config server
37 | . The change will not reflect in the the applications
38 | . Now refresh the properties using a POST request:
39 | [source,java]
40 | ----
41 | curl -X POST http://localhost:8080/bus/refresh
42 | ----
43 | . The changed property should now reflect on all instances of the application.
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/sample-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.bk
7 | sample-config
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | sample-config
12 | Sample Config Server
13 |
14 |
15 | org.bk
16 | spring-cloud-bus-sample
17 | 1.0.0-SNAPSHOT
18 | ../pom.xml
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-config-server
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-actuator
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.bk
7 | sample-service
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | sample-service
12 | Sample Service
13 |
14 |
15 | org.bk
16 | spring-cloud-bus-sample
17 | 1.0.0-SNAPSHOT
18 | ../pom.xml
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-config-client
29 |
30 |
31 | org.springframework.cloud
32 | spring-cloud-starter-bus-amqp
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 | org.bk
8 | spring-cloud-bus-sample
9 | pom
10 | 1.0.0-SNAPSHOT
11 | Spring-Cloud Bus Sample
12 |
13 |
14 | sample-config
15 | sample-service
16 |
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-parent
21 | 1.4.0.RELEASE
22 |
23 |
24 |
25 | UTF-8
26 | 1.8
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-web
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-actuator
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 | org.assertj
49 | assertj-core
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.cloud
58 | spring-cloud-dependencies
59 | Brixton.SR4
60 | pom
61 | import
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.springframework.boot
70 | spring-boot-maven-plugin
71 |
72 |
73 |
74 |
75 |
76 | spring-release
77 | http://repo.spring.io/release/
78 |
79 |
80 | spring-milestones
81 | Spring Milestones
82 | http://repo.spring.io/milestone
83 |
84 | false
85 |
86 |
87 |
88 |
89 |
90 | spring-release
91 | http://repo.spring.io/release/
92 |
93 |
94 | spring-milestones
95 | Spring Milestones
96 | http://repo.spring.io/milestone
97 |
98 | false
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------