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

2024-04-27

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

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

任何帮助将不胜感激。


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

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

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


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

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

并打电话BlockHound.install()在你的 main 方法中,在引导 Spring Boot 应用程序之前:

@SpringBootApplication
public class BlockhoundDemoApplication {

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

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

}

如需进一步参考,您可以参考:

  • 我的文章@https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1 https://medium.com/@domenicosibilio/blockhound-detect-blocking-calls-in-reactive-code-before-its-too-late-6472f8ad50c1我在其中解释了如何在 Spring Boot 2.2 应用程序中集成和自定义 BlockHound 以进行 JUnit 测试;
  • 我的演示项目位于 GitHub https://github.com/dsibilio/blockhound-demo集成和定制 BlockHound 以进行 JUnit 测试;
  • the BlockHound 文档 https://github.com/reactor/BlockHound/tree/master/docs(参见支持的测试框架部分);
  • the BlockHound Gitter 频道 https://gitter.im/reactor/BlockHound,您可以在这里询问有关 BlockHound 的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐