diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 9b4a4316d..8cb328656 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -222,6 +222,13 @@ ${redisson.version} + + + cn.iocoder.cloud + yudao-spring-boot-starter-rpc + ${revision} + + diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index a5850bd42..e13419176 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -21,6 +21,7 @@ yudao-spring-boot-starter-protection yudao-spring-boot-starter-job yudao-spring-boot-starter-mq + yudao-spring-boot-starter-rpc yudao-spring-boot-starter-excel yudao-spring-boot-starter-test diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml b/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml new file mode 100644 index 000000000..42389560c --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-rpc/pom.xml @@ -0,0 +1,42 @@ + + + + yudao-framework + cn.iocoder.cloud + ${revision} + + 4.0.0 + yudao-spring-boot-starter-rpc + jar + + ${project.artifactId} + + OpenFeign:提供 RESTful API 的调用 + Dubbo:提供 Dubbo RPC 的调用 + + https://github.com/YunaiV/ruoyi-vue-pro + + + + cn.iocoder.cloud + yudao-common + + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + com.alibaba.cloud + spring-cloud-starter-dubbo + + + diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java new file mode 100644 index 000000000..516acc537 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/config/package-info.java @@ -0,0 +1,4 @@ +/** + * 占坑 TODO + */ +package cn.iocoder.yudao.framework.rpc.config; diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java new file mode 100644 index 000000000..e8e494628 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/package-info.java @@ -0,0 +1,4 @@ +/** + * 占坑 TODO + */ +package cn.iocoder.yudao.framework.rpc.core; diff --git a/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java new file mode 100644 index 000000000..af81e0be6 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-rpc/src/main/java/cn/iocoder/yudao/framework/rpc/core/util/FeignUtils.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.framework.rpc.core.util; + +import cn.hutool.core.util.ReflectUtil; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import feign.RequestTemplate; +import feign.template.HeaderTemplate; +import feign.template.Literal; +import feign.template.Template; +import feign.template.TemplateChunk; + +import java.util.List; +import java.util.Map; + +/** + * {@link feign.Feign} 工具类 + * + * @author 芋道源码 + */ +public class FeignUtils { + + /** + * 添加 JSON 格式的 Header + * + * @param requestTemplate 请求 + * @param name header 名 + * @param value header 值 + */ + @SuppressWarnings("unchecked") + public static void createJsonHeader(RequestTemplate requestTemplate, String name, Object value) { + if (value == null) { + return; + } + // 添加 header + String valueStr = JsonUtils.toJsonString(value); + requestTemplate.header(name, valueStr); + // fix:由于 OpenFeign 针对 { 会进行分词,所以需要反射修改 + // 具体分析,可见 https://zhuanlan.zhihu.com/p/360501330 文档 + Map headers = (Map) + ReflectUtil.getFieldValue(requestTemplate, "headers"); + HeaderTemplate template = headers.get(name); + List