update 更新动态日志开关与订阅服务配置
parent
d728d116e9
commit
30f3fe7a26
|
|
@ -22,19 +22,27 @@ dubbo:
|
||||||
name: dubbo
|
name: dubbo
|
||||||
# dubbo 协议端口(-1表示自增端口,从20880开始)
|
# dubbo 协议端口(-1表示自增端口,从20880开始)
|
||||||
port: -1
|
port: -1
|
||||||
# 挂载到 Spring Cloud 注册中心
|
# 注册中心配置
|
||||||
registry:
|
registry:
|
||||||
address: nacos://${spring.cloud.nacos.server-addr}
|
address: nacos://${spring.cloud.nacos.server-addr}
|
||||||
group: DUBBO_GROUP
|
group: DUBBO_GROUP
|
||||||
|
# 消费者相关配置
|
||||||
consumer:
|
consumer:
|
||||||
|
# 结果缓存(LRU算法)
|
||||||
cache: true
|
cache: true
|
||||||
|
# 支持校验注解
|
||||||
validation: true
|
validation: true
|
||||||
|
# 超时时间
|
||||||
timeout: 3000
|
timeout: 3000
|
||||||
|
# 初始化检查
|
||||||
check: false
|
check: false
|
||||||
scan:
|
scan:
|
||||||
|
# 接口实现类扫描
|
||||||
base-packages: com.ruoyi.**.dubbo
|
base-packages: com.ruoyi.**.dubbo
|
||||||
cloud:
|
# 自定义配置
|
||||||
subscribed-services: ${dubbo.application.name}
|
custom:
|
||||||
|
# 全局请求log
|
||||||
|
request-log: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
main:
|
main:
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ spring:
|
||||||
# 环境配置
|
# 环境配置
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
|
|
||||||
|
--- # dubbo 订阅配置
|
||||||
|
dubbo:
|
||||||
|
cloud:
|
||||||
|
# 需要远程调用的服务 多个用逗号分割
|
||||||
|
subscribed-services: ruoyi-system
|
||||||
|
|
||||||
--- # nacos 配置
|
--- # nacos 配置
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,37 @@
|
||||||
package com.ruoyi.common.dubbo.filter;
|
package com.ruoyi.common.dubbo.filter;
|
||||||
|
|
||||||
import com.ruoyi.common.core.utils.JsonUtils;
|
import com.ruoyi.common.core.utils.JsonUtils;
|
||||||
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import com.ruoyi.common.dubbo.properties.DubboCustomProperties;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.common.constants.CommonConstants;
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
import org.apache.dubbo.common.extension.Activate;
|
import org.apache.dubbo.common.extension.Activate;
|
||||||
import org.apache.dubbo.rpc.*;
|
import org.apache.dubbo.rpc.*;
|
||||||
import org.apache.dubbo.rpc.service.GenericService;
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dubbo日志过滤器
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Activate(group = { CommonConstants.PROVIDER, CommonConstants.CONSUMER })
|
@Activate(group = { CommonConstants.PROVIDER, CommonConstants.CONSUMER })
|
||||||
public class DubboRequestFilter implements Filter {
|
public class DubboRequestFilter implements Filter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
||||||
//打印入参日志
|
DubboCustomProperties properties = SpringUtils.getBean(DubboCustomProperties.class);
|
||||||
log.info("DUBBO - 服务入参: InterfaceName=[{}],MethodName=[{}],Parameter=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), invocation.getArguments());
|
if (!properties.getRequestLog()) {
|
||||||
//开始时间
|
// 未开启则跳过日志逻辑
|
||||||
|
return invoker.invoke(invocation);
|
||||||
|
}
|
||||||
|
String client = CommonConstants.PROVIDER;
|
||||||
|
if (RpcContext.getContext().isConsumerSide()) {
|
||||||
|
client = CommonConstants.CONSUMER;
|
||||||
|
}
|
||||||
|
String baselog = "Client[" + client + "],InterfaceName=[" + invocation.getInvoker().getInterface().getName() + "],MethodName=[" + invocation.getMethodName() + "]";
|
||||||
|
log.info("DUBBO - 服务调用: {},Parameter=[{}]", baselog, invocation.getArguments());
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
// 执行接口调用逻辑
|
// 执行接口调用逻辑
|
||||||
Result result = invoker.invoke(invocation);
|
Result result = invoker.invoke(invocation);
|
||||||
|
|
@ -23,10 +39,9 @@ public class DubboRequestFilter implements Filter {
|
||||||
long elapsed = System.currentTimeMillis() - startTime;
|
long elapsed = System.currentTimeMillis() - startTime;
|
||||||
// 如果发生异常 则打印异常日志
|
// 如果发生异常 则打印异常日志
|
||||||
if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
|
if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
|
||||||
log.error("DUBBO - 执行异常: ", result.getException());
|
log.error("DUBBO - 服务异常: {},Exception=[{}]", baselog, result.getException());
|
||||||
} else {
|
} else {
|
||||||
//打印响应日志
|
log.info("DUBBO - 服务响应: {},SpendTime=[{}ms],Response=[{}]", baselog, elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
|
||||||
log.info("DUBBO - 服务响应: InterfaceName=[{}],MethodName=[{}],SpendTime=[{}ms],Response=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.ruoyi.common.dubbo.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义配置
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@RefreshScope
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "dubbo.custom")
|
||||||
|
public class DubboCustomProperties {
|
||||||
|
|
||||||
|
private Boolean requestLog;
|
||||||
|
}
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.ruoyi.common.dubbo.properties.DubboCustomProperties
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>ruoyi-common-dubbo</artifactId>
|
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class AsyncLogService {
|
public class AsyncLogService {
|
||||||
|
|
||||||
@DubboReference(async = true)
|
@DubboReference
|
||||||
private RemoteLogService remoteLogService;
|
private RemoteLogService remoteLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ spring:
|
||||||
# 环境配置
|
# 环境配置
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
|
|
||||||
|
--- # dubbo 订阅配置
|
||||||
|
dubbo:
|
||||||
|
cloud:
|
||||||
|
# 需要远程调用的服务 多个用逗号分割
|
||||||
|
subscribed-services: ruoyi-auth,ruoyi-system
|
||||||
|
|
||||||
--- # nacos 配置
|
--- # nacos 配置
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ spring:
|
||||||
# 环境配置
|
# 环境配置
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
|
|
||||||
|
--- # dubbo 订阅配置
|
||||||
|
dubbo:
|
||||||
|
cloud:
|
||||||
|
# 需要远程调用的服务 多个用逗号分割
|
||||||
|
subscribed-services: ruoyi-system
|
||||||
|
|
||||||
--- # nacos 配置
|
--- # nacos 配置
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,12 @@ swagger:
|
||||||
license: ${swagger.license}
|
license: ${swagger.license}
|
||||||
licenseUrl: ${swagger.licenseUrl}
|
licenseUrl: ${swagger.licenseUrl}
|
||||||
|
|
||||||
|
--- # dubbo 订阅配置
|
||||||
|
dubbo:
|
||||||
|
cloud:
|
||||||
|
# 需要远程调用的服务 多个用逗号分割
|
||||||
|
subscribed-services: ruoyi-system
|
||||||
|
|
||||||
--- # nacos 配置
|
--- # nacos 配置
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,12 @@ swagger:
|
||||||
license: ${swagger.license}
|
license: ${swagger.license}
|
||||||
licenseUrl: ${swagger.licenseUrl}
|
licenseUrl: ${swagger.licenseUrl}
|
||||||
|
|
||||||
|
--- # dubbo 订阅配置
|
||||||
|
dubbo:
|
||||||
|
cloud:
|
||||||
|
# 需要远程调用的服务 多个用逗号分割
|
||||||
|
subscribed-services: ruoyi-file
|
||||||
|
|
||||||
--- # nacos 配置
|
--- # nacos 配置
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue