【问题标题】:Receiving Cancel Signal from a Successful Request从成功的请求中接收取消信号
【发布时间】:2019-10-16 05:14:06
【问题描述】:

我正在尝试将一些 WebFilters 创建到 Spring-Boot WebFlux 应用程序中,我注意到我开发的所有 post 操作仅适用于 Actuator 的端点,但它们不适用于我自己的端点。

在分析过程中,我注意到当我调用 Actuator 端点(例如:health)时,Mono 已按预期完成。然而,当我调用我的端点时,单声道发出了一个取消信号。 这是预期的行为吗?

依赖关系:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
    </parent>

    <groupId>test</groupId>
    <artifactId>tests</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

我的代码:

@SpringBootApplication
@RestController
public class Main {

    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }

    @Bean
    public WebFilter newFilter() {
        return (exchange, chain) -> chain.filter(exchange)
                                         .doFinally(signalType -> {
                                             LOGGER.info("Status: {}", signalType);
                                         })
                                         .doAfterSuccessOrError(((aVoid, throwable) -> {
                                             LOGGER.info("Only actuators come to here.");
                                         }));
    }


    @GetMapping("/hello")
    public Mono<String> probe() {
        return Mono.fromCallable(() -> "world");
    }
}
curl http://localhost:8080/test

控制台: 状态:取消

curl http://localhost:8080/actuator/health

控制台: 只有执行器来到这里。 状态:完成

我希望所有端点调用都会执行 doAfterSuccessOrError 函数,但只有执行器的 Health 会执行。

【问题讨论】:

    标签: spring spring-boot spring-webflux


    【解决方案1】:

    好像是SpringBoot 2.1.5的bug,升级到2.1.7就可以解决这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多