从成功请求接收取消信号



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

在我的分析过程中,我注意到当我调用执行器端点(例如:运行状况(时,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 函数,但只有执行器的运行状况会执行。

这似乎是 SpringBoot 2.1.5 的错误,升级到 2.1.7 将解决此问题

最新更新