mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 12:28:10 +00:00
add 集成 dubbo 实现高性能 rpc 远程调用
update 回滚到 dubbo2.7.8 add 增加 dubbo 日志打印过滤器 update 优化代码 dubbo 用法
This commit is contained in:
40
ruoyi-common/ruoyi-common-dubbo/pom.xml
Normal file
40
ruoyi-common/ruoyi-common-dubbo/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-dubbo
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,34 @@
|
||||
package com.ruoyi.common.dubbo.filter;
|
||||
|
||||
import com.ruoyi.common.core.utils.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.rpc.*;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
||||
@Slf4j
|
||||
@Activate(group = { CommonConstants.PROVIDER, CommonConstants.CONSUMER })
|
||||
public class DubboRequestFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||
//打印入参日志
|
||||
log.info("DUBBO - 服务入参: InterfaceName=[{}],MethodName=[{}],Parameter=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), invocation.getArguments());
|
||||
//开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//执行接口调用逻辑
|
||||
Result result = invoker.invoke(invocation);
|
||||
//调用耗时
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
//如果发生异常 则打印异常日志
|
||||
if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
|
||||
log.error("DUBBO - 执行异常: ", result.getException());
|
||||
} else {
|
||||
//打印响应日志
|
||||
log.info("DUBBO - 服务响应: InterfaceName=[{}],MethodName=[{}],SpendTime=[{}ms],Response=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1 @@
|
||||
dubboRequestFilter=com.ruoyi.common.dubbo.filter.DubboRequestFilter
|
@@ -0,0 +1 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
|
Reference in New Issue
Block a user