mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-26 16:26:41 +08:00
后台目录结构大调整,让结构更清晰
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
//package org.jeecg.fallback;
|
||||
//
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//import reactor.core.publisher.Mono;
|
||||
//
|
||||
///**
|
||||
// * 响应超时熔断处理器【升级springboot2.6.6后,此类作废】
|
||||
// *
|
||||
// * @author zyf
|
||||
// */
|
||||
//@RestController
|
||||
//public class FallbackController {
|
||||
//
|
||||
// /**
|
||||
// * 全局熔断处理
|
||||
// * @return
|
||||
// */
|
||||
// @RequestMapping("/fallback")
|
||||
// public Mono<String> fallback() {
|
||||
// return Mono.just("访问超时,请稍后再试!");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * demo熔断处理
|
||||
// * @return
|
||||
// */
|
||||
// @RequestMapping("/demo/fallback")
|
||||
// public Mono<String> fallback2() {
|
||||
// return Mono.just("访问超时,请稍后再试!");
|
||||
// }
|
||||
//}
|
||||
@ -0,0 +1,33 @@
|
||||
//package org.jeecg.fallback;
|
||||
//
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.reactive.function.BodyInserters;
|
||||
//import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||
//import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
//import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
//import reactor.core.publisher.Mono;
|
||||
//
|
||||
//import java.util.Optional;
|
||||
//
|
||||
//import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR;
|
||||
//
|
||||
///**
|
||||
// * @author scott
|
||||
// * @date 2020/05/26
|
||||
// * Hystrix 降级处理
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class HystrixFallbackHandler implements HandlerFunction<ServerResponse> {
|
||||
// @Override
|
||||
// public Mono<ServerResponse> handle(ServerRequest serverRequest) {
|
||||
// Optional<Object> originalUris = serverRequest.attribute(GATEWAY_ORIGINAL_REQUEST_URL_ATTR);
|
||||
//
|
||||
// originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
|
||||
//
|
||||
// return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
|
||||
// .header("Content-Type","text/plain; charset=utf-8").body(BodyInserters.fromObject("访问超时,请稍后再试"));
|
||||
// }
|
||||
//}
|
||||
@ -0,0 +1,45 @@
|
||||
package org.jeecg.fallback.sentinel;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
|
||||
import org.jeecg.common.enums.SentinelErrorInfoEnum;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Description: 自定义Sentinel全局异常(需要启动Sentinel客户端)
|
||||
* @author: zyf
|
||||
* @date: 2022/02/18
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewaySentinelExceptionConfig {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
BlockRequestHandler blockRequestHandler = (serverWebExchange, ex) -> {
|
||||
String msg;
|
||||
SentinelErrorInfoEnum errorInfoEnum = SentinelErrorInfoEnum.getErrorByException(ex);
|
||||
if (ObjectUtil.isNotEmpty(errorInfoEnum)) {
|
||||
msg = errorInfoEnum.getError();
|
||||
} else {
|
||||
msg = "未知限流降级";
|
||||
}
|
||||
HashMap<String, String> map = new HashMap(5);
|
||||
map.put("code", HttpStatus.TOO_MANY_REQUESTS.toString());
|
||||
map.put("message", msg);
|
||||
//自定义异常处理
|
||||
return ServerResponse.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(map));
|
||||
};
|
||||
|
||||
GatewayCallbackManager.setBlockHandler(blockRequestHandler);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
//package org.jeecg.fallback.sentinel;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
|
||||
//import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.cloud.commons.util.InetUtils;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.reactive.function.BodyInserters;
|
||||
//import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
//import org.springframework.web.server.ServerWebExchange;
|
||||
//import reactor.core.publisher.Mono;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//
|
||||
///**
|
||||
// * 自定义限流返回信息
|
||||
// * @author scott
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class SentinelBlockRequestHandler implements BlockRequestHandler {
|
||||
// @Autowired
|
||||
// private InetUtils inetUtils;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void doInit() {
|
||||
// System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable ex) {
|
||||
// String resultString = "{\"code\":403,\"message\":\"服务开启限流保护,请稍后再试!\"}";
|
||||
// return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS).contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(resultString));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
Reference in New Issue
Block a user