如何将 BlockHound 添​​加到 Spring Boot 应用程序以检测阻塞调用? [英] How to add BlockHound to a spring boot app to detect blocking calls?

查看:27
本文介绍了如何将 BlockHound 添​​加到 Spring Boot 应用程序以检测阻塞调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 BlockHound 添​​加到 Spring Boot 应用程序以检测阻塞调用?

How to add BlockHound to spring boot app to detect blocking calls ?

我没有找到 Spring Boot 应用程序的任何示例:https://github.com/reactor/BlockHound/blob/master/文档/quick_start.md

I didn't find any examples for spring boot apps: https://github.com/reactor/BlockHound/blob/master/docs/quick_start.md

任何帮助将不胜感激.

推荐答案

恕我直言,最明智的选择是在 JUnit 测试执行代码时启用 BlockHound.

IMHO, the wisest choice would be to enable BlockHound while the code is being exercised by JUnit tests.

为此,您只需导入 https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound-junit-platform 与测试范围的依赖关系,它会在您启动 JUnit 测试套件时自动初始化 BlockHound:

To do so you simply need to import the https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound-junit-platform dependency with test scope, which automatically initializes BlockHound when you launch your JUnit tests suite:

<dependency>
  <groupId>io.projectreactor.tools</groupId>
  <artifactId>blockhound-junit-platform</artifactId>
  <version>1.0.0.RC1</version>
  <scope>test</scope>
</dependency>

<小时>

或者,如果您打算一直使用 BlockHound - 而不仅仅是在测试期间 - 您应该导入以下依赖项:


Alternatively, if you intend to use BlockHound at all times - and not only during tests - you should instead import the following dependency:

<dependency>
  <groupId>io.projectreactor.tools</groupId>
  <artifactId>blockhound</artifactId>
  <version>1.0.0.RC1</version>
</dependency>

并在您的主方法中调用 BlockHound.install(),就在引导您的 Spring Boot 应用程序之前:

And call BlockHound.install() in your main method, just before bootstrapping your Spring Boot application:

@SpringBootApplication
public class BlockhoundDemoApplication {

    public static void main(String[] args) {
        BlockHound.install();

        SpringApplication.run(BlockhoundDemoApplication.class, args);
    }

}

进一步参考可以参考:

  • my article @ https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1 where I explain how to integrate and customize BlockHound for JUnit testing in a Spring Boot 2.2 application;
  • my demo project over at GitHub that integrates and customizes BlockHound for JUnit testing;
  • the BlockHound docs (see the supported testing frameworks section);
  • the BlockHound Gitter channel, where you can ask questions about BlockHound.

这篇关于如何将 BlockHound 添​​加到 Spring Boot 应用程序以检测阻塞调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆