How to add BlockHound to a spring boot app to detect blocking calls?
Asked Answered
O

1

7

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

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

Any help will be appreciated.

Onestep answered 19/9, 2019 at 14:51 Comment(0)
H
12

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

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>


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>

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);
    }

}

For further reference you can refer to:

Hooknosed answered 22/9, 2019 at 18:52 Comment(2)
Would you be able to share how to do this in gradle?Othelia
@Othelia Use either implementation or testimplementation in your dependencies with either oi.projectreactor.tools:blockhound:1.0.4.RELEASE or io.projectreactor.tools:blockhound-junit-platform:1.0.4.RELEASE and then do BlockHound.install() in either your main application code or your test.Tabatha

© 2022 - 2024 — McMap. All rights reserved.