mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 04:18:07 +00:00
add 集成 dubbo 实现高性能 rpc 远程调用
update 回滚到 dubbo2.7.8 add 增加 dubbo 日志打印过滤器 update 优化代码 dubbo 用法
This commit is contained in:
@@ -34,6 +34,12 @@
|
||||
<artifactId>ruoyi-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package com.ruoyi.common.security.annotation;
|
||||
|
||||
import com.ruoyi.common.security.feign.FeignAutoConfiguration;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@@ -18,8 +16,6 @@ import java.lang.annotation.*;
|
||||
@MapperScan("com.ruoyi.**.mapper")
|
||||
// 开启线程异步执行
|
||||
@EnableAsync
|
||||
// 自动加载类
|
||||
@Import({FeignAutoConfiguration.class})
|
||||
public @interface EnableCustomConfig {
|
||||
|
||||
}
|
||||
|
@@ -1,27 +0,0 @@
|
||||
package com.ruoyi.common.security.annotation;
|
||||
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 自定义feign注解
|
||||
* 添加basePackages路径
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@EnableFeignClients
|
||||
public @interface EnableRyFeignClients {
|
||||
String[] value() default {};
|
||||
|
||||
String[] basePackages() default {"com.ruoyi"};
|
||||
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
|
||||
Class<?>[] defaultConfiguration() default {};
|
||||
|
||||
Class<?>[] clients() default {};
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.common.security.feign;
|
||||
|
||||
/**
|
||||
* Feign 配置注册
|
||||
*
|
||||
* @author ruoyi
|
||||
**/
|
||||
//@Configuration
|
||||
//public class DubboAutoConfiguration {
|
||||
// @Bean
|
||||
// public Filter requestInterceptor() {
|
||||
// return new DubboRequestFilter();
|
||||
// }
|
||||
//}
|
@@ -0,0 +1,49 @@
|
||||
//package com.ruoyi.common.security.feign;
|
||||
//
|
||||
//import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
//import com.ruoyi.common.core.utils.ServletUtils;
|
||||
//import com.ruoyi.common.core.utils.StringUtils;
|
||||
//import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||
//import org.apache.dubbo.common.constants.CommonConstants;
|
||||
//import org.apache.dubbo.common.extension.Activate;
|
||||
//import org.apache.dubbo.rpc.*;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * feign 请求拦截器
|
||||
// *
|
||||
// * @author ruoyi
|
||||
// */
|
||||
//@Activate(group = {CommonConstants.CONSUMER}, order = -10000)
|
||||
//@Component
|
||||
//public class DubboRequestFilter implements Filter {
|
||||
// @Override
|
||||
// public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||
// //执行接口调用逻辑
|
||||
// Result result = invoker.invoke(invocation);
|
||||
// HttpServletRequest httpServletRequest = ServletUtils.getRequest();
|
||||
// if (httpServletRequest != null) {
|
||||
// Map<String, String> headers = ServletUtils.getHeaders(httpServletRequest);
|
||||
// // 传递用户信息请求头,防止丢失
|
||||
// String userId = headers.get(SecurityConstants.DETAILS_USER_ID);
|
||||
// if (StringUtils.isNotEmpty(userId)) {
|
||||
// RpcContext.getServerContext().setAttachment(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
// }
|
||||
// String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
|
||||
// if (StringUtils.isNotEmpty(userName)) {
|
||||
// RpcContext.getServerContext().setAttachment(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
// }
|
||||
// String authentication = headers.get(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
// if (StringUtils.isNotEmpty(authentication)) {
|
||||
// RpcContext.getServerContext().setAttachment(SecurityConstants.AUTHORIZATION_HEADER, authentication);
|
||||
// }
|
||||
//
|
||||
// // 配置客户端IP
|
||||
// RpcContext.getServerContext().setAttachment("X-Forwarded-For", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
@@ -1,18 +0,0 @@
|
||||
package com.ruoyi.common.security.feign;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Feign 配置注册
|
||||
*
|
||||
* @author ruoyi
|
||||
**/
|
||||
@Configuration
|
||||
public class FeignAutoConfiguration {
|
||||
@Bean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return new FeignRequestInterceptor();
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package com.ruoyi.common.security.feign;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* feign 请求拦截器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class FeignRequestInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
HttpServletRequest httpServletRequest = ServletUtils.getRequest();
|
||||
if (StringUtils.isNotNull(httpServletRequest)) {
|
||||
Map<String, String> headers = ServletUtils.getHeaders(httpServletRequest);
|
||||
// 传递用户信息请求头,防止丢失
|
||||
String userId = headers.get(SecurityConstants.DETAILS_USER_ID);
|
||||
if (StringUtils.isNotEmpty(userId)) {
|
||||
requestTemplate.header(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
}
|
||||
String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
|
||||
if (StringUtils.isNotEmpty(userName)) {
|
||||
requestTemplate.header(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
}
|
||||
String authentication = headers.get(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
if (StringUtils.isNotEmpty(authentication)) {
|
||||
requestTemplate.header(SecurityConstants.AUTHORIZATION_HEADER, authentication);
|
||||
}
|
||||
|
||||
// 配置客户端IP
|
||||
requestTemplate.header("X-Forwarded-For", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user