add 集成 dubbo 实现高性能 rpc 远程调用

update 回滚到 dubbo2.7.8

add 增加 dubbo 日志打印过滤器

update 优化代码 dubbo 用法
This commit is contained in:
疯狂的狮子li
2022-01-04 20:53:33 +08:00
parent 189c00d794
commit 4c20bf7137
39 changed files with 509 additions and 395 deletions

View File

@@ -1,28 +1,20 @@
package com.ruoyi.system.api;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件服务
*
* @author ruoyi
* @author Lion Li
*/
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {
/**
* 上传文件
*
* @param file 文件信息
* @return 结果
*/
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
SysFile upload(MultipartFile file);
}

View File

@@ -1,23 +1,15 @@
package com.ruoyi.system.api;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog;
import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
/**
* 日志服务
*
* @author ruoyi
* @author Lion Li
*/
@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
public interface RemoteLogService {
/**
* 保存系统日志
*
@@ -25,8 +17,7 @@ public interface RemoteLogService {
* @param source 请求来源
* @return 结果
*/
@PostMapping("/operlog")
R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
Boolean saveLog(SysOperLog sysOperLog, String source);
/**
* 保存访问记录
@@ -35,6 +26,5 @@ public interface RemoteLogService {
* @param source 请求来源
* @return 结果
*/
@PostMapping("/logininfor")
R<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
Boolean saveLogininfor(SysLogininfor sysLogininfor, String source);
}

View File

@@ -1,21 +1,15 @@
package com.ruoyi.system.api;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* 用户服务
*
* @author ruoyi
* @author Lion Li
*/
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
/**
* 通过用户名查询用户信息
*
@@ -23,8 +17,7 @@ public interface RemoteUserService {
* @param source 请求来源
* @return 结果
*/
@GetMapping("/user/info/{username}")
R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
LoginUser getUserInfo(String username, String source);
/**
* 注册用户信息
@@ -33,6 +26,5 @@ public interface RemoteUserService {
* @param source 请求来源
* @return 结果
*/
@PostMapping("/user/register")
R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
Boolean registerUserInfo(SysUser sysUser, String source);
}

View File

@@ -1,30 +0,0 @@
package com.ruoyi.system.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件服务降级处理
*
* @author ruoyi
*/
@Slf4j
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
@Override
public RemoteFileService create(Throwable throwable) {
log.error("文件服务调用失败:{}", throwable.getMessage());
return new RemoteFileService() {
@Override
public R<SysFile> upload(MultipartFile file) {
return R.fail("上传文件失败:" + throwable.getMessage());
}
};
}
}

View File

@@ -1,36 +0,0 @@
package com.ruoyi.system.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteLogService;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 日志服务降级处理
*
* @author ruoyi
*/
@Slf4j
@Component
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {
@Override
public RemoteLogService create(Throwable throwable) {
log.error("日志服务调用失败:{}", throwable.getMessage());
return new RemoteLogService() {
@Override
public R<Boolean> saveLog(SysOperLog sysOperLog, String source) {
return null;
}
@Override
public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source) {
return null;
}
};
}
}

View File

@@ -1,35 +0,0 @@
package com.ruoyi.system.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 用户服务降级处理
*
* @author ruoyi
*/
@Slf4j
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
@Override
public RemoteUserService create(Throwable throwable) {
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteUserService() {
@Override
public R<LoginUser> getUserInfo(String username, String source) {
return R.fail("获取用户失败:" + throwable.getMessage());
}
@Override
public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
return R.fail("注册用户失败:" + throwable.getMessage());
}
};
}
}