mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-27 11:59:37 +08:00
remove 重大改动 删除sentinel所有相关功能(为什么删除 查看文档详细说明 https://plus-doc.dromara.org/#/questions/sentinel_404)
This commit is contained in:
@@ -13,8 +13,6 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class RuoYiGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
// 标记 sentinel 类型为 网关
|
||||
System.setProperty("csp.sentinel.app.type", "1");
|
||||
SpringApplication application = new SpringApplication(RuoYiGatewayApplication.class);
|
||||
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
application.run(args);
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package org.dromara.gateway.config;
|
||||
|
||||
import org.dromara.gateway.handler.SentinelFallbackHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* 网关限流配置
|
||||
@@ -13,9 +9,5 @@ import org.springframework.core.annotation.Order;
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewayConfig {
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public SentinelFallbackHandler sentinelGatewayExceptionHandler() {
|
||||
return new SentinelFallbackHandler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.dromara.gateway.handler;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import org.dromara.gateway.utils.WebFluxUtils;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 自定义限流异常处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SentinelFallbackHandler implements WebExceptionHandler {
|
||||
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
|
||||
return WebFluxUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
if (exchange.getResponse().isCommitted()) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
if (!BlockException.isBlockException(ex)) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
return handleBlockedRequest(exchange, ex).flatMap(response -> writeResponse(response, exchange));
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable) {
|
||||
return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user