Revert "[重大更新] 使用 spring feign 替代 HttpServiceClient (功能太新 支持不完全 使用成本太高)"

This reverts commit 485c2001
This commit is contained in:
疯狂的狮子Li
2026-03-24 18:01:00 +08:00
parent e44e5727a6
commit 2fdcf44dbb
62 changed files with 1161 additions and 817 deletions

View File

@@ -1,15 +1,13 @@
package org.dromara.resource.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.annotation.RemoteHttpService;
import org.dromara.resource.api.domain.RemoteFile;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
import java.util.List;
@@ -18,8 +16,8 @@ import java.util.List;
*
* @author Lion Li
*/
@FeignClient(contextId = "remoteFileService", name = "ruoyi-resource", path = "/remote/file",
fallbackFactory = RemoteFileServiceFallbackFactory.class, primary = false)
@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteFileServiceFallback.class)
@HttpExchange("/remote/file")
public interface RemoteFileService {
/**
@@ -28,7 +26,7 @@ public interface RemoteFileService {
* @param file 文件信息
* @return 结果
*/
@PostMapping("/upload")
@PostExchange("/upload")
RemoteFile upload(@RequestParam String name, @RequestParam String originalFilename,
@RequestParam String contentType, @RequestBody byte[] file) throws ServiceException;
@@ -38,7 +36,7 @@ public interface RemoteFileService {
* @param ossIds ossId串逗号分隔
* @return url串逗号分隔
*/
@GetMapping("/select-url-by-ids")
@GetExchange("/select-url-by-ids")
String selectUrlByIds(@RequestParam String ossIds);
/**
@@ -47,7 +45,6 @@ public interface RemoteFileService {
* @param ossIds ossId串逗号分隔
* @return 列表
*/
@GetMapping("/select-by-ids")
@GetExchange("/select-by-ids")
List<RemoteFile> selectByIds(@RequestParam String ossIds);
}

View File

@@ -0,0 +1,53 @@
package org.dromara.resource.api;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.resource.api.domain.RemoteFile;
import java.util.List;
/**
* 文件服务熔断降级.
*
* @author Lion Li
*/
@Slf4j
public class RemoteFileServiceFallback implements RemoteFileService {
/**
* 上传文件
*
* @param file 文件信息
* @return 结果
*/
@Override
public RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) {
log.warn("服务调用异常 -> 降级处理");
return null;
}
/**
* 通过ossId查询对应的url
*
* @param ossIds ossId串逗号分隔
* @return url串逗号分隔
*/
@Override
public String selectUrlByIds(String ossIds) {
log.warn("服务调用异常 -> 降级处理");
return StringUtils.EMPTY;
}
/**
* 通过ossId查询列表
*
* @param ossIds ossId串逗号分隔
* @return 列表
*/
@Override
public List<RemoteFile> selectByIds(String ossIds) {
log.warn("服务调用异常 -> 降级处理");
return List.of();
}
}

View File

@@ -1,40 +0,0 @@
package org.dromara.resource.api;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.resource.api.domain.RemoteFile;
import org.springframework.cloud.openfeign.FallbackFactory;
import java.util.List;
/**
* 文件服务 fallback factory.
*
* @author Lion Li
*/
@Slf4j
public class RemoteFileServiceFallbackFactory implements FallbackFactory<RemoteFileService> {
@Override
public RemoteFileService create(Throwable cause) {
return new RemoteFileService() {
@Override
public RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) {
log.warn("文件服务调用失败, 已触发 fallback", cause);
return null;
}
@Override
public String selectUrlByIds(String ossIds) {
log.warn("文件服务调用失败, 已触发 fallback", cause);
return StringUtils.EMPTY;
}
@Override
public List<RemoteFile> selectByIds(String ossIds) {
log.warn("文件服务调用失败, 已触发 fallback", cause);
return List.of();
}
};
}
}

View File

@@ -1,17 +1,18 @@
package org.dromara.resource.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.annotation.RemoteHttpService;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
/**
* 邮件服务
*
* @author Lion Li
*/
@FeignClient(contextId = "remoteMailService", name = "ruoyi-resource", path = "/remote/mail", primary = false)
@RemoteHttpService("ruoyi-resource")
@HttpExchange("/remote/mail")
public interface RemoteMailService {
/**
@@ -21,9 +22,7 @@ public interface RemoteMailService {
* @param subject 标题
* @param text 内容
*/
@PostMapping("/send")
@PostExchange("/send")
void send(@RequestParam String to, @RequestParam String subject, @RequestParam String text) throws ServiceException;
}

View File

@@ -1,13 +1,10 @@
package org.dromara.resource.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.dromara.common.core.annotation.RemoteHttpService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
import java.util.List;
@@ -16,8 +13,8 @@ import java.util.List;
*
* @author Lion Li
*/
@FeignClient(contextId = "remoteMessageService", name = "ruoyi-resource", path = "/remote/message",
fallbackFactory = RemoteMessageServiceFallbackFactory.class, primary = false)
@RemoteHttpService(value = "ruoyi-resource", fallback = RemoteMessageServiceFallback.class)
@HttpExchange("/remote/message")
public interface RemoteMessageService {
/**
@@ -26,7 +23,7 @@ public interface RemoteMessageService {
* @param sessionKey session主键 一般为用户id
* @param message 消息文本
*/
@PostMapping("/publish-message")
@PostExchange("/publish-message")
void publishMessage(@RequestBody List<Long> sessionKey, @RequestParam String message);
/**
@@ -34,7 +31,6 @@ public interface RemoteMessageService {
*
* @param message 消息内容
*/
@PostMapping("/publish-all")
@PostExchange("/publish-all")
void publishAll(@RequestParam String message);
}

View File

@@ -0,0 +1,35 @@
package org.dromara.resource.api;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* 消息服务熔断降级.
*
* @author Lion Li
*/
@Slf4j
public class RemoteMessageServiceFallback implements RemoteMessageService {
/**
* 发送消息
*
* @param sessionKey session主键 一般为用户id
* @param message 消息文本
*/
@Override
public void publishMessage(List<Long> sessionKey, String message) {
log.warn("消息服务调用失败, 已触发熔断降级");
}
/**
* 发布订阅的消息(群发)
*
* @param message 消息内容
*/
@Override
public void publishAll(String message) {
log.warn("消息服务调用失败, 已触发熔断降级");
}
}

View File

@@ -1,30 +0,0 @@
package org.dromara.resource.api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import java.util.List;
/**
* 消息服务 fallback factory.
*
* @author Lion Li
*/
@Slf4j
public class RemoteMessageServiceFallbackFactory implements FallbackFactory<RemoteMessageService> {
@Override
public RemoteMessageService create(Throwable cause) {
return new RemoteMessageService() {
@Override
public void publishMessage(List<Long> sessionKey, String message) {
log.warn("消息服务调用失败, 已触发 fallback", cause);
}
@Override
public void publishAll(String message) {
log.warn("消息服务调用失败, 已触发 fallback", cause);
}
};
}
}

View File

@@ -1,16 +1,13 @@
package org.dromara.resource.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.dromara.common.core.annotation.RemoteHttpService;
import org.dromara.resource.api.domain.RemoteSms;
import org.dromara.resource.api.domain.RemoteSmsBatch;
import org.dromara.resource.api.domain.RemoteSmsDelayBatch;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;
import java.util.LinkedHashMap;
import java.util.List;
@@ -20,7 +17,8 @@ import java.util.List;
*
* @author Feng
*/
@FeignClient(contextId = "remoteSmsService", name = "ruoyi-resource", path = "/inner/remote/resource/sms", primary = false)
@RemoteHttpService("ruoyi-resource")
@HttpExchange("/inner/remote/resource/sms")
public interface RemoteSmsService {
/**
@@ -30,7 +28,7 @@ public interface RemoteSmsService {
* @param message 短信内容
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/send-text")
@PostExchange("/send-text")
RemoteSms sendMessage(@RequestParam String phone, @RequestParam String message);
/**
@@ -40,7 +38,7 @@ public interface RemoteSmsService {
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/send-vars")
@PostExchange("/send-vars")
RemoteSms sendMessage(@RequestParam String phone, @RequestBody LinkedHashMap<String, String> messages);
/**
@@ -51,7 +49,7 @@ public interface RemoteSmsService {
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/send-template")
@PostExchange("/send-template")
RemoteSms sendMessage(@RequestParam String phone, @RequestParam String templateId,
@RequestBody LinkedHashMap<String, String> messages);
@@ -62,7 +60,7 @@ public interface RemoteSmsService {
* @param message 短信内容
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/message-texting")
@PostExchange("/message-texting")
RemoteSms messageTexting(@RequestBody List<String> phones, @RequestParam String message);
/**
@@ -73,7 +71,7 @@ public interface RemoteSmsService {
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/message-texting-template")
@PostExchange("/message-texting-template")
default RemoteSms messageTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
return messageTextingTemplate(new RemoteSmsBatch(phones, templateId, messages));
}
@@ -84,7 +82,7 @@ public interface RemoteSmsService {
* @param request 群发模板短信请求
* @return 封装了短信发送结果的 RemoteSms 对象
*/
@PostMapping("/message-texting-template")
@PostExchange("/message-texting-template")
RemoteSms messageTextingTemplate(@RequestBody RemoteSmsBatch request);
/**
@@ -93,7 +91,7 @@ public interface RemoteSmsService {
* @param phone 目标手机号
* @param message 短信内容
*/
@PostMapping("/send-async-text")
@PostExchange("/send-async-text")
void sendMessageAsync(@RequestParam String phone, @RequestParam String message);
/**
@@ -103,7 +101,7 @@ public interface RemoteSmsService {
* @param templateId 短信模板ID
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
*/
@PostMapping("/send-async-template")
@PostExchange("/send-async-template")
void sendMessageAsync(@RequestParam String phone, @RequestParam String templateId,
@RequestBody LinkedHashMap<String, String> messages);
@@ -114,7 +112,7 @@ public interface RemoteSmsService {
* @param message 短信内容
* @param delayedTime 延迟发送时间(毫秒)
*/
@PostMapping("/delay-text")
@PostExchange("/delay-text")
void delayMessage(@RequestParam String phone, @RequestParam String message, @RequestParam Long delayedTime);
/**
@@ -125,7 +123,7 @@ public interface RemoteSmsService {
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
* @param delayedTime 延迟发送时间(毫秒)
*/
@PostMapping("/delay-template")
@PostExchange("/delay-template")
void delayMessage(@RequestParam String phone, @RequestParam String templateId,
@RequestBody LinkedHashMap<String, String> messages, @RequestParam Long delayedTime);
@@ -136,7 +134,7 @@ public interface RemoteSmsService {
* @param message 短信内容
* @param delayedTime 延迟发送时间(毫秒)
*/
@PostMapping("/delay-message-texting")
@PostExchange("/delay-message-texting")
void delayMessageTexting(@RequestBody List<String> phones, @RequestParam String message, @RequestParam Long delayedTime);
/**
@@ -147,7 +145,7 @@ public interface RemoteSmsService {
* @param messages 短信模板参数,使用 LinkedHashMap 以保持参数顺序
* @param delayedTime 延迟发送时间(毫秒)
*/
@PostMapping("/delay-message-texting-template")
@PostExchange("/delay-message-texting-template")
default void delayMessageTexting(List<String> phones, String templateId,
LinkedHashMap<String, String> messages, Long delayedTime) {
delayMessageTextingTemplate(new RemoteSmsDelayBatch(phones, templateId, messages, delayedTime));
@@ -158,7 +156,7 @@ public interface RemoteSmsService {
*
* @param request 延迟群发模板短信请求
*/
@PostMapping("/delay-message-texting-template")
@PostExchange("/delay-message-texting-template")
void delayMessageTextingTemplate(@RequestBody RemoteSmsDelayBatch request);
/**
@@ -166,7 +164,7 @@ public interface RemoteSmsService {
*
* @param phone 手机号
*/
@PostMapping("/add-blacklist-one")
@PostExchange("/add-blacklist-one")
void addBlacklist(@RequestParam String phone);
/**
@@ -174,7 +172,7 @@ public interface RemoteSmsService {
*
* @param phones 手机号列表
*/
@PostMapping("/add-blacklist-list")
@PostExchange("/add-blacklist-list")
void addBlacklist(@RequestBody List<String> phones);
/**
@@ -182,7 +180,7 @@ public interface RemoteSmsService {
*
* @param phone 手机号
*/
@PostMapping("/remove-blacklist-one")
@PostExchange("/remove-blacklist-one")
void removeBlacklist(@RequestParam String phone);
/**
@@ -190,8 +188,7 @@ public interface RemoteSmsService {
*
* @param phones 手机号
*/
@PostMapping("/remove-blacklist-list")
@PostExchange("/remove-blacklist-list")
void removeBlacklist(@RequestBody List<String> phones);
}