Commit fe8518f2f20e94e9a76a92fd4da2b1309cfe1617
1 parent
bf46e788
【3.2.0 版本发布】微服务测试示例调整,更便于理解和测试
Showing
5 changed files
with
20 additions
and
42 deletions
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/constant/CloudConstant.java
@@ -6,11 +6,6 @@ package org.jeecg.modules.test.constant; | @@ -6,11 +6,6 @@ package org.jeecg.modules.test.constant; | ||
6 | public interface CloudConstant { | 6 | public interface CloudConstant { |
7 | 7 | ||
8 | /** | 8 | /** |
9 | - * 微服务名【对应模块jeecg-boot-module-demo】 | ||
10 | - */ | ||
11 | - public final static String SERVER_NAME_JEECGDEMO = "jeecg-demo"; | ||
12 | - | ||
13 | - /** | ||
14 | * MQ测试队列名字 | 9 | * MQ测试队列名字 |
15 | */ | 10 | */ |
16 | public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; | 11 | public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClient.java
@@ -2,6 +2,7 @@ package org.jeecg.modules.test.feign.client; | @@ -2,6 +2,7 @@ package org.jeecg.modules.test.feign.client; | ||
2 | 2 | ||
3 | import org.jeecg.common.api.vo.Result; | 3 | import org.jeecg.common.api.vo.Result; |
4 | 4 | ||
5 | +import org.jeecg.common.constant.ServiceNameConstants; | ||
5 | import org.jeecg.config.FeignConfig; | 6 | import org.jeecg.config.FeignConfig; |
6 | import org.jeecg.modules.test.constant.CloudConstant; | 7 | import org.jeecg.modules.test.constant.CloudConstant; |
7 | import org.jeecg.modules.test.feign.factory.JeecgTestClientFactory; | 8 | import org.jeecg.modules.test.feign.factory.JeecgTestClientFactory; |
@@ -15,10 +16,10 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -15,10 +16,10 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
15 | /** | 16 | /** |
16 | * 常规feign接口定义 | 17 | * 常规feign接口定义 |
17 | */ | 18 | */ |
18 | -@FeignClient(value = CloudConstant.SERVER_NAME_JEECGDEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class) | 19 | +@FeignClient(value = ServiceNameConstants.SERVICE_DEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class) |
19 | @Component | 20 | @Component |
20 | public interface JeecgTestClient { | 21 | public interface JeecgTestClient { |
21 | 22 | ||
22 | @GetMapping(value = "/test/getMessage") | 23 | @GetMapping(value = "/test/getMessage") |
23 | - Result<Object> getMessage(@RequestParam(value = "name",required = false) String name); | 24 | + String getMessage(@RequestParam(value = "name",required = false) String name); |
24 | } | 25 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClientDyn.java deleted
1 | -//package org.jeecg.modules.test.feign.client; | ||
2 | -// | ||
3 | -//import org.jeecg.common.api.vo.Result; | ||
4 | -//import org.springframework.web.bind.annotation.GetMapping; | ||
5 | -//import org.springframework.web.bind.annotation.PostMapping; | ||
6 | -//import org.springframework.web.bind.annotation.RequestParam; | ||
7 | -// | ||
8 | -///** | ||
9 | -// * 动态feign接口定义 | ||
10 | -// */ | ||
11 | -//public interface JeecgTestClientDyn { | ||
12 | -// | ||
13 | -// @GetMapping(value = "/test/getMessage") | ||
14 | -// Result<String> getMessage(@RequestParam(value = "name",required = false) String name); | ||
15 | -//} |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/controller/JeecgTestFeignController.java
@@ -21,17 +21,20 @@ public class JeecgTestFeignController { | @@ -21,17 +21,20 @@ public class JeecgTestFeignController { | ||
21 | 21 | ||
22 | @Autowired | 22 | @Autowired |
23 | private JeecgTestClient jeecgTestClient; | 23 | private JeecgTestClient jeecgTestClient; |
24 | -// @Autowired | ||
25 | -// private RabbitMqClient rabbitMqClient; | ||
26 | -// @Autowired | ||
27 | -// private JeecgFeignService jeecgFeignService; | ||
28 | 24 | ||
25 | + /** | ||
26 | + * 熔断: fallbackFactory优先于 @SentinelResource | ||
27 | + * | ||
28 | + * @param name | ||
29 | + * @return | ||
30 | + */ | ||
29 | @GetMapping("/getMessage") | 31 | @GetMapping("/getMessage") |
30 | - @ApiOperation(value = "测试feign", notes = "测试feign") | 32 | + @ApiOperation(value = "测试feign调用demo服务1", notes = "测试feign @SentinelResource熔断写法 | 测试熔断关闭jeecg-demo服务") |
31 | @SentinelResource(value = "test_more_getMessage", fallback = "getDefaultUser") | 33 | @SentinelResource(value = "test_more_getMessage", fallback = "getDefaultUser") |
32 | - public Result<Object> getMessage(@RequestParam(value = "name", required = false) String name) { | 34 | + public Result<String> getMessage(@RequestParam(value = "name", required = false) String name) { |
33 | log.info("---------Feign fallbackFactory优先级高于@SentinelResource-----------------"); | 35 | log.info("---------Feign fallbackFactory优先级高于@SentinelResource-----------------"); |
34 | - return jeecgTestClient.getMessage("fegin——jeecg-boot1"); | 36 | + String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!"); |
37 | + return Result.OK(null, resultMsg); | ||
35 | } | 38 | } |
36 | 39 | ||
37 | /** | 40 | /** |
@@ -41,20 +44,14 @@ public class JeecgTestFeignController { | @@ -41,20 +44,14 @@ public class JeecgTestFeignController { | ||
41 | * @return | 44 | * @return |
42 | */ | 45 | */ |
43 | @GetMapping("/getMessage2") | 46 | @GetMapping("/getMessage2") |
44 | - @ApiOperation(value = "测试feign2", notes = "测试feign2") | ||
45 | - public Result<Object> getMessage2(@RequestParam(value = "name", required = false) String name) { | 47 | + @ApiOperation(value = "测试feign调用demo服务2", notes = "测试feign fallbackFactory熔断写法 | 测试熔断关闭jeecg-demo服务") |
48 | + public Result<String> getMessage2(@RequestParam(value = "name", required = false) String name) { | ||
46 | log.info("---------测试 Feign fallbackFactory-----------------"); | 49 | log.info("---------测试 Feign fallbackFactory-----------------"); |
47 | - return jeecgTestClient.getMessage("fegin——jeecg-boot2"); | 50 | + String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!"); |
51 | + return Result.OK(null, resultMsg); | ||
48 | } | 52 | } |
49 | 53 | ||
50 | 54 | ||
51 | -// @GetMapping("getMessage2") | ||
52 | -// @ApiOperation(value = "测试动态feign", notes = "测试动态feign") | ||
53 | -// public Result<String> getMessage2() { | ||
54 | -// JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO); | ||
55 | -// return myClientDyn.getMessage("动态fegin——jeecg-boot2"); | ||
56 | -// } | ||
57 | - | ||
58 | @GetMapping("/fallback") | 55 | @GetMapping("/fallback") |
59 | @ApiOperation(value = "测试熔断", notes = "测试熔断") | 56 | @ApiOperation(value = "测试熔断", notes = "测试熔断") |
60 | @SentinelResource(value = "test_more_fallback", fallback = "getDefaultUser") | 57 | @SentinelResource(value = "test_more_fallback", fallback = "getDefaultUser") |
@@ -73,6 +70,6 @@ public class JeecgTestFeignController { | @@ -73,6 +70,6 @@ public class JeecgTestFeignController { | ||
73 | */ | 70 | */ |
74 | public Result<Object> getDefaultUser(String name) { | 71 | public Result<Object> getDefaultUser(String name) { |
75 | log.info("熔断,默认回调函数"); | 72 | log.info("熔断,默认回调函数"); |
76 | - return Result.OK("访问超时, 自定义 @SentinelResource Fallback"); | 73 | + return Result.error(null, "访问超时, 自定义 @SentinelResource Fallback"); |
77 | } | 74 | } |
78 | } | 75 | } |
jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/fallback/JeecgTestFallback.java
@@ -19,7 +19,7 @@ public class JeecgTestFallback implements JeecgTestClient { | @@ -19,7 +19,7 @@ public class JeecgTestFallback implements JeecgTestClient { | ||
19 | 19 | ||
20 | 20 | ||
21 | @Override | 21 | @Override |
22 | - public Result<Object> getMessage(String name) { | ||
23 | - return Result.OK("访问超时, 自定义FallbackFactory"); | 22 | + public String getMessage(String name) { |
23 | + return "访问超时, 自定义FallbackFactory"; | ||
24 | } | 24 | } |
25 | } | 25 | } |