2

I would like to disable the rabbit health check in my default RabbitMockConfiguration. We have a Configuration that is imported via @Import. Unfortunately the Configuration does not prevent the health check from being added to the health indicator as that happens once spring-rabbit is in the classpath.

We have the workaround, that we add a properties file in every service using that Configuration, which disables the property management.health.rabbit.enabled, but for us it would be much nicer to be able to disable that heathcheck on configuration level.

I thought about the tests with @TestPropertySource(properties = ["management.health.rabbit.enabled=false"]), but I could not find an equivalent to use for the a @Configuration, as @PropertySource expects a location for a properties file and does not accept single properties.

Any idea what we can do?

Spring boot version: 2.2.4
Spring amqp version: 2.2.3
Spring Version: 5.2.3

Ruth
  • 856
  • 2
  • 13
  • 26

2 Answers2

5

If you want to change the behaviour of the health check, I'd rather override the health check so that it states Rabbit is in mock mode.

To do so, just create a HealthIndicator bean named rabbitHealthIndicator:

@Bean
public HealthIndicator rabbitHealthIndicator() {
    return () -> Health.up().withDetail("version", "mock").build();
}

This has the effect of switching the production one and exposes the fact the app is running with a mock.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
-1

I guess you should add 'ApplicationListener' and add the implementation to 'src/main/resources/META-INF/spring.factories' to your module with MockReddisConfiguration. This is described in more detail here

Maxim Popov
  • 1,167
  • 5
  • 9
  • wow that sounds very heavy :( is there nothing easier, like for Test the TestPropertySource – Ruth Feb 17 '20 at 08:01
  • DoI understand right that you want to run the application with redis mock (e.g. for developing) and you manually add @Import(MockConfig) to your app? Maybe you are able to use some special profiles (e.g. "dev"), mark the configuration as @Profile("DEV") and add required properties to "DEV" section in application.yml, and run the app with "DEV' spring profile when need mock redis? – Maxim Popov Feb 17 '20 at 18:43
  • then again I would have to write this in the application.yml of every service, I would like to have it at the point where it is needed. Also a point of readability there as well as you have it all together instead of spread over files – Ruth Feb 18 '20 at 12:27