Skip to content

Commit 98248ab

Browse files
committed
Spring Cloud构建微服务架构(七)消息总线(Rabbit、Kafka)
1 parent 769276c commit 98248ab

File tree

11 files changed

+234
-0
lines changed

11 files changed

+234
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>config-client-eureka-kafka</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>config-client-eureka-kafka</name>
12+
<description>Spring Cloud project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.7.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.retry</groupId>
29+
<artifactId>spring-retry</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-aop</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-actuator</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.cloud</groupId>
45+
<artifactId>spring-cloud-starter-config</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.cloud</groupId>
49+
<artifactId>spring-cloud-starter-eureka</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.cloud</groupId>
53+
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
54+
</dependency>
55+
</dependencies>
56+
57+
<dependencyManagement>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.springframework.cloud</groupId>
61+
<artifactId>spring-cloud-dependencies</artifactId>
62+
<version>Brixton.SR5</version>
63+
<type>pom</type>
64+
<scope>import</scope>
65+
</dependency>
66+
</dependencies>
67+
</dependencyManagement>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
7+
@EnableDiscoveryClient
8+
@SpringBootApplication
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
new SpringApplicationBuilder(Application.class).web(true).run(args);
13+
}
14+
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.didispace.web;
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+
@RefreshScope
9+
@RestController
10+
public class TestController {
11+
12+
@Value("${from}")
13+
private String from;
14+
15+
@RequestMapping("/from")
16+
public String from() {
17+
return this.from;
18+
}
19+
20+
public void setFrom(String from) {
21+
this.from = from;
22+
}
23+
24+
public String getFrom() {
25+
return from;
26+
}
27+
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
spring.application.name=didispace
2+
server.port=7002
3+
4+
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
5+
6+
spring.cloud.config.discovery.enabled=true
7+
spring.cloud.config.discovery.serviceId=config-server
8+
spring.cloud.config.profile=dev
9+
10+
spring.cloud.config.failFast=true
11+
12+
#kafka
13+
spring.cloud.stream.kafka.binder.zk-nodes=localhost:2181
14+
spring.cloud.stream.kafka.binder.brokers=localhost:9092
15+
16+
spring.cloud.bus.trace.enabled=true
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>config-server-eureka-kafka</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>config-server-eureka-kafka</name>
12+
<description>Spring Cloud project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.7.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-config-server</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.cloud</groupId>
33+
<artifactId>spring-cloud-starter-eureka</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.cloud</groupId>
37+
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
38+
</dependency>
39+
</dependencies>
40+
41+
<dependencyManagement>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.springframework.cloud</groupId>
45+
<artifactId>spring-cloud-dependencies</artifactId>
46+
<version>Brixton.SR5</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
</dependencies>
51+
</dependencyManagement>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-maven-plugin</artifactId>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.cloud.config.server.EnableConfigServer;
7+
8+
@EnableDiscoveryClient
9+
@EnableConfigServer
10+
@SpringBootApplication
11+
public class Application {
12+
13+
public static void main(String[] args) {
14+
new SpringApplicationBuilder(Application.class).web(true).run(args);
15+
}
16+
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spring.application.name=config-server
2+
server.port=7001
3+
4+
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
5+
6+
# git¹ÜÀíÅäÖÃ
7+
spring.cloud.config.server.git.uri=http://git.oschina.net/didispace/SpringCloud-Learning/
8+
spring.cloud.config.server.git.searchPaths=Chapter1-1-7/config-repo
9+
spring.cloud.config.server.git.username=username
10+
spring.cloud.config.server.git.password=password
11+
12+
#kafka
13+
spring.cloud.stream.kafka.binder.zk-nodes=localhost:2181
14+
spring.cloud.stream.kafka.binder.brokers=localhost:9092
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-dev
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-prod
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local

0 commit comments

Comments
 (0)