File tree Expand file tree Collapse file tree 11 files changed +74
-12
lines changed
src/main/java/com/coderqian/dubboapi/service
java/com/coderqian/dubboconsumer/controller
java/com/coderqian/dubboprovider Expand file tree Collapse file tree 11 files changed +74
-12
lines changed Original file line number Diff line number Diff line change 2525 <dependencies >
2626 <dependency >
2727 <groupId >org.springframework.boot</groupId >
28- <artifactId >spring-boot-starter</artifactId >
28+ <artifactId >spring-boot-starter-web </artifactId >
2929 </dependency >
3030
3131 <dependency >
32- <groupId >org.springframework.boot</groupId >
33- <artifactId >spring-boot-starter-web</artifactId >
32+ <groupId >io.swagger</groupId >
33+ <artifactId >swagger-annotations</artifactId >
34+ <version >1.5.20</version >
3435 </dependency >
3536 </dependencies >
3637
Original file line number Diff line number Diff line change 33/**
44 * @author qianliqing
55 * @date 2018/11/29 1:55 PM
6- * email: qianliqing@hyperchain .com
6+ * email: qianlq0824@gmail .com
77 */
88
99public interface TestService {
Original file line number Diff line number Diff line change 2020 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
2121 <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
2222 <java .version>1.8</java .version>
23+ <spring-cloud .version>Finchley.RELEASE</spring-cloud .version>
2324 </properties >
2425
2526 <dependencies >
3435 <artifactId >spring-boot-starter-web</artifactId >
3536 </dependency >
3637
38+ <dependency >
39+ <groupId >org.springframework.cloud</groupId >
40+ <artifactId >spring-cloud-starter-netflix-hystrix</artifactId >
41+ <version >2.0.1.RELEASE</version >
42+ </dependency >
3743 </dependencies >
3844
45+
46+ <dependencyManagement >
47+ <dependencies >
48+ <dependency >
49+ <groupId >org.springframework.cloud</groupId >
50+ <artifactId >spring-cloud-dependencies</artifactId >
51+ <version >${spring-cloud.version} </version >
52+ <type >pom</type >
53+ <scope >import</scope >
54+ </dependency >
55+ </dependencies >
56+ </dependencyManagement >
57+
3958 <build >
4059 <plugins >
4160 <plugin >
4564 </plugins >
4665 </build >
4766
48-
4967</project >
Original file line number Diff line number Diff line change 22
33import com .alibaba .dubbo .config .annotation .Reference ;
44import com .coderqian .dubboapi .service .TestService ;
5+ import com .netflix .hystrix .contrib .javanica .annotation .HystrixCommand ;
56import org .springframework .web .bind .annotation .RequestMapping ;
67import org .springframework .web .bind .annotation .RequestMethod ;
78import org .springframework .web .bind .annotation .RestController ;
89
910/**
1011 * @author qianliqing
1112 * @date 2018/11/29 1:52 PM
12- * email: qianliqing@hyperchain .com
13+ * email: qianlq0824@gmail .com
1314 */
1415
1516@ RestController
@@ -19,8 +20,13 @@ public class TestController {
1920 @ Reference
2021 private TestService testService ;
2122
23+ @ HystrixCommand (fallbackMethod = "testError" )
2224 @ RequestMapping (value = "/hello" , method = RequestMethod .GET )
2325 public String test (String text ) {
2426 return testService .test (text );
2527 }
28+
29+ private String testError (String text ) {
30+ return "失败" + text ;
31+ }
2632}
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ dubbo.application.id=dubbo-customer
77dubbo.application.name =dubbo-customer
88# 注册中心
99dubbo.registry.address =zookeeper://127.0.0.1:2181
10+ dubbo.registry.timeout =60000
11+ dubbo.registry.group =dubbo
12+ dubbo.registry.check =false
1013
1114# 生产者提供的协议id
1215dubbo.protocol.id =dubbo-provider
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
99 <dubbo : application name =" dubbo-customer" />
1010
1111 <!-- 注册中心配置,使用zookeeper注册中心暴露服务地址 -->
12- <dubbo : registry address =" zookeeper://127.0.0.1:2181" timeout =" 60000" group =" dubbo" />
12+ <dubbo : registry address =" zookeeper://127.0.0.1:2181" timeout =" 60000" group =" dubbo" check = " false " />
1313
1414 <!-- 关闭服务消费方所有服务的启动检查。dubbo缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止Spring初始化完成 -->
1515 <dubbo : consumer check =" false" />
Original file line number Diff line number Diff line change 2020 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
2121 <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
2222 <java .version>1.8</java .version>
23+ <spring-cloud .version>Finchley.RELEASE</spring-cloud .version>
2324 </properties >
2425
2526 <dependencies >
3435 <artifactId >spring-boot-starter-actuator</artifactId >
3536 </dependency >
3637
38+ <!-- Hystrix依赖 -->
39+ <dependency >
40+ <groupId >org.springframework.cloud</groupId >
41+ <artifactId >spring-cloud-starter-netflix-hystrix</artifactId >
42+ <version >2.0.1.RELEASE</version >
43+ </dependency >
44+
3745 <dependency >
3846 <groupId >org.apache.zookeeper</groupId >
3947 <artifactId >zookeeper</artifactId >
7179 </dependency >
7280 </dependencies >
7381
82+ <dependencyManagement >
83+ <dependencies >
84+ <dependency >
85+ <groupId >org.springframework.cloud</groupId >
86+ <artifactId >spring-cloud-dependencies</artifactId >
87+ <version >${spring-cloud.version} </version >
88+ <type >pom</type >
89+ <scope >import</scope >
90+ </dependency >
91+ </dependencies >
92+ </dependencyManagement >
93+
7494 <build >
7595 <plugins >
7696 <plugin >
80100 </plugins >
81101 </build >
82102
83-
84103</project >
Original file line number Diff line number Diff line change 33import com .alibaba .dubbo .config .spring .context .annotation .EnableDubbo ;
44import org .springframework .boot .SpringApplication ;
55import org .springframework .boot .autoconfigure .SpringBootApplication ;
6+ import org .springframework .cloud .netflix .hystrix .EnableHystrix ;
67
78@ EnableDubbo
9+ @ EnableHystrix
810@ SpringBootApplication
911//@ImportResource({"classpath:dubbo/dubbo-provider.xml"})
1012public class DubboProviderApplication {
Original file line number Diff line number Diff line change 22
33import com .alibaba .dubbo .config .annotation .Service ;
44import com .coderqian .dubboapi .service .TestService ;
5+ import com .netflix .hystrix .contrib .javanica .annotation .HystrixCommand ;
6+ import com .netflix .hystrix .contrib .javanica .annotation .HystrixProperty ;
7+ import io .swagger .annotations .ApiParam ;
58
69/**
710 * @author qianliqing
811 * @date 2018/11/29 12:53 PM
9- * email: qianliqing@hyperchain .com
12+ * email: qianlq0824@gmail .com
1013 */
1114
1215@ Service
1316public class TestServiceImpl implements TestService {
1417
18+ @ HystrixCommand (commandProperties = {
19+ @ HystrixProperty (name = "circuitBreaker.requestVolumeThreshold" , value = "3" ),
20+ @ HystrixProperty (name = "execution.isolation.thread.timeoutInMilliseconds" , value = "2000" )
21+ })
1522 @ Override
16- public String test (String text ) {
23+ public String test (@ ApiParam ( value = "测试数据" , required = true ) String text ) {
1724 return text ;
1825 }
1926}
Original file line number Diff line number Diff line change @@ -7,8 +7,14 @@ dubbo.application.id=dubbo-provider
77dubbo.application.name =dubbo-provider
88# 注册中心
99dubbo.registry.address =zookeeper://127.0.0.1:2181
10+ dubbo.registry.timeout =60000
11+ dubbo.registry.group =dubbo
12+ dubbo.registry.check =false
13+
1014dubbo.server =true
1115# 生产者暴露给消费者协议
1216dubbo.protocol.name =dubbo
1317# 生产者暴露给消费者端口
14- dubbo.protocol.port =20880
18+ dubbo.protocol.port =20880
19+
20+ logging.config =classpath:log4j2.xml
You can’t perform that action at this time.
0 commit comments