diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/constant/CloudConstant.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/constant/CloudConstant.java index 63b3eda..9009507 100644 --- a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/constant/CloudConstant.java +++ b/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; public interface CloudConstant { /** - * 微服务名【对应模块jeecg-boot-module-demo】 - */ - public final static String SERVER_NAME_JEECGDEMO = "jeecg-demo"; - - /** * MQ测试队列名字 */ public final static String MQ_JEECG_PLACE_ORDER = "jeecg_place_order"; diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClient.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClient.java index d37fd5d..19bd6f7 100644 --- a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClient.java +++ b/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; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.ServiceNameConstants; import org.jeecg.config.FeignConfig; import org.jeecg.modules.test.constant.CloudConstant; import org.jeecg.modules.test.feign.factory.JeecgTestClientFactory; @@ -15,10 +16,10 @@ import org.springframework.web.bind.annotation.RequestParam; /** * 常规feign接口定义 */ -@FeignClient(value = CloudConstant.SERVER_NAME_JEECGDEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class) +@FeignClient(value = ServiceNameConstants.SERVICE_DEMO, configuration = FeignConfig.class,fallbackFactory = JeecgTestClientFactory.class) @Component public interface JeecgTestClient { @GetMapping(value = "/test/getMessage") - Result<Object> getMessage(@RequestParam(value = "name",required = false) String name); + String getMessage(@RequestParam(value = "name",required = false) String name); } diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClientDyn.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClientDyn.java deleted file mode 100644 index 3a31690..0000000 --- a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/client/JeecgTestClientDyn.java +++ /dev/null @@ -1,15 +0,0 @@ -//package org.jeecg.modules.test.feign.client; -// -//import org.jeecg.common.api.vo.Result; -//import org.springframework.web.bind.annotation.GetMapping; -//import org.springframework.web.bind.annotation.PostMapping; -//import org.springframework.web.bind.annotation.RequestParam; -// -///** -// * 动态feign接口定义 -// */ -//public interface JeecgTestClientDyn { -// -// @GetMapping(value = "/test/getMessage") -// Result<String> getMessage(@RequestParam(value = "name",required = false) String name); -//} diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/controller/JeecgTestFeignController.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/controller/JeecgTestFeignController.java index 8696d30..2c963a8 100644 --- a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/controller/JeecgTestFeignController.java +++ b/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 { @Autowired private JeecgTestClient jeecgTestClient; -// @Autowired -// private RabbitMqClient rabbitMqClient; -// @Autowired -// private JeecgFeignService jeecgFeignService; + /** + * 熔断: fallbackFactory优先于 @SentinelResource + * + * @param name + * @return + */ @GetMapping("/getMessage") - @ApiOperation(value = "测试feign", notes = "测试feign") + @ApiOperation(value = "测试feign调用demo服务1", notes = "测试feign @SentinelResource熔断写法 | 测试熔断关闭jeecg-demo服务") @SentinelResource(value = "test_more_getMessage", fallback = "getDefaultUser") - public Result<Object> getMessage(@RequestParam(value = "name", required = false) String name) { + public Result<String> getMessage(@RequestParam(value = "name", required = false) String name) { log.info("---------Feign fallbackFactory优先级高于@SentinelResource-----------------"); - return jeecgTestClient.getMessage("fegin——jeecg-boot1"); + String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!"); + return Result.OK(null, resultMsg); } /** @@ -41,20 +44,14 @@ public class JeecgTestFeignController { * @return */ @GetMapping("/getMessage2") - @ApiOperation(value = "测试feign2", notes = "测试feign2") - public Result<Object> getMessage2(@RequestParam(value = "name", required = false) String name) { + @ApiOperation(value = "测试feign调用demo服务2", notes = "测试feign fallbackFactory熔断写法 | 测试熔断关闭jeecg-demo服务") + public Result<String> getMessage2(@RequestParam(value = "name", required = false) String name) { log.info("---------测试 Feign fallbackFactory-----------------"); - return jeecgTestClient.getMessage("fegin——jeecg-boot2"); + String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!"); + return Result.OK(null, resultMsg); } -// @GetMapping("getMessage2") -// @ApiOperation(value = "测试动态feign", notes = "测试动态feign") -// public Result<String> getMessage2() { -// JeecgTestClientDyn myClientDyn = jeecgFeignService.newInstance(JeecgTestClientDyn.class, CloudConstant.SERVER_NAME_JEECGDEMO); -// return myClientDyn.getMessage("动态fegin——jeecg-boot2"); -// } - @GetMapping("/fallback") @ApiOperation(value = "测试熔断", notes = "测试熔断") @SentinelResource(value = "test_more_fallback", fallback = "getDefaultUser") @@ -73,6 +70,6 @@ public class JeecgTestFeignController { */ public Result<Object> getDefaultUser(String name) { log.info("熔断,默认回调函数"); - return Result.OK("访问超时, 自定义 @SentinelResource Fallback"); + return Result.error(null, "访问超时, 自定义 @SentinelResource Fallback"); } } diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/fallback/JeecgTestFallback.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/fallback/JeecgTestFallback.java index daf5d3d..62441cb 100644 --- a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-test/jeecg-cloud-test-more/src/main/java/org/jeecg/modules/test/feign/fallback/JeecgTestFallback.java +++ b/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 { @Override - public Result<Object> getMessage(String name) { - return Result.OK("访问超时, 自定义FallbackFactory"); + public String getMessage(String name) { + return "访问超时, 自定义FallbackFactory"; } }