Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway integration #1430

Closed
levin950825 opened this issue Apr 25, 2020 · 1 comment
Closed

gateway integration #1430

levin950825 opened this issue Apr 25, 2020 · 1 comment
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control integration/spring-cloud Issue related to Spring Cloud Alibaba integration

Comments

@levin950825
Copy link

使用最新版本Spring Boot,然后网关结合官方案例结果不符合预期结果,是版本造成的BUG还是我配置有误?
Use the latest version of spring boot, and the gateway combined with the official case results do not meet the expected results. Is the bug caused by the version or am I misconfigured?

Which Component
eg. Nacos Discovery, Sentinel

Describe what problem you have encountered

project version

<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
spring:
  cloud:
    sentinel:
      transport:
        port: 8719
        dashboard: localhost:8080
      filter:
        enabled: false
      eager: true
/**
 * 限流规则配置类
 */
@Configuration
public class GatewayConfiguration {

    private final List<ViewResolver> viewResolvers;
    private final ServerCodecConfigurer serverCodecConfigurer;

    /**
     * 构造器
     *
     * @param viewResolversProvider
     * @param serverCodecConfigurer
     */
    public GatewayConfiguration(ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                ServerCodecConfigurer serverCodecConfigurer) {
        this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
        this.serverCodecConfigurer = serverCodecConfigurer;
    }

    /**
     * 限流异常处理器
     *
     * @return
     */
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
        // Register the block exception handler for Spring Cloud Gateway.
        return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
    }

    /**
     * 限流过滤器
     *
     * @return
     */
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public GlobalFilter sentinelGatewayFilter() {
        return new SentinelGatewayFilter();
    }

    /**
     * Spring 容器初始化的时候执行该方法
     */
    @PostConstruct
    public void doInit() {
        // 加载网关限流规则
        initGatewayRules();
    }

    /**
     * 网关限流规则
     */
    private void initGatewayRules() {
        Set<GatewayFlowRule> rules = new HashSet<>();
        /*
            resource:资源名称,可以是网关中的 route 名称或者用户自定义的 API 分组名称
            count:限流阈值
            intervalSec:统计时间窗口,单位是秒,默认是 1 秒
         */
        rules.add(new GatewayFlowRule("order-service")
                .setCount(3) // 限流阈值
                .setIntervalSec(60)); // 统计时间窗口,单位是秒,默认是 1 秒
        // 加载网关限流规则
        GatewayRuleManager.loadRules(rules);
    }

}

Multiple access: http: / / localhost: 9001 / order / 1 result does not trigger current restriction

Describe what information you have read
eg. I have read the reference doc of Sentinel

@cdfive cdfive added area/gateway-flow-control Issues or PRs related to API gateway flow control integration/spring-cloud Issue related to Spring Cloud Alibaba integration labels May 2, 2020
@sczyh30
Copy link
Member

sczyh30 commented Jun 15, 2020

You may check whether there are any errors in your logs. Refer https://github.com/alibaba/Sentinel/wiki/Logs

@sczyh30 sczyh30 closed this as completed Aug 6, 2020
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
[ISSUE alibaba#1429]Update Broker's Topic Read or Write Perm failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control integration/spring-cloud Issue related to Spring Cloud Alibaba integration
Projects
None yet
Development

No branches or pull requests

3 participants