引入sentinel依赖
This commit is contained in:
parent
da376dd3c7
commit
de7103b5dd
@ -148,6 +148,16 @@
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
@ -0,0 +1,36 @@
|
||||
package net.jieyuu.exception;
|
||||
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
||||
import net.jieyuu.enums.BizCodeEnum;
|
||||
import net.jieyuu.utils.CommonUtil;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* sentinel 限流异常处理器
|
||||
*/
|
||||
@Component
|
||||
public class XdclassUrlBlockHandler implements BlockExceptionHandler {
|
||||
@Override
|
||||
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
|
||||
JsonData jsondata = null;
|
||||
if (e instanceof FlowException) {
|
||||
jsondata = JsonData.buildResult(BizCodeEnum.CONTROL_FLOW);
|
||||
} else if (e instanceof DegradeException) {
|
||||
jsondata = JsonData.buildResult(BizCodeEnum.CONTROL_DEGRADE);
|
||||
} else if (e instanceof AuthorityException) {
|
||||
jsondata = JsonData.buildResult(BizCodeEnum.CONTROL_AUTH);
|
||||
}
|
||||
httpServletResponse.setStatus(200);
|
||||
CommonUtil.sendJsonMessage(httpServletResponse, jsondata);
|
||||
}
|
||||
}
|
@ -31,6 +31,17 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
Loading…
Reference in New Issue
Block a user