0

I am using Spring boot 2.2.9.RELEASE and Spring Cloud Hoxton.SR7. I am using Spring Cloud Bus to signal all my containers in a docker swarm stack and when deployed in production with a running RabbitMQ cluster things work perfectly!

I am using the RabbitMQ implementation via the spring-cloud-starter-bus-amqp Spring Boot starter. We occasionally run tests without needing the bus. There is a spring boot flag for this:

spring.cloud.bus.enabled=false

this disables the bus, but rabbitMQ still starts, and spits out connection refused errors. I had to also add:

rabbitmq.autoStarting=false

I tried fussing around with disabling RabbitMQ's auto configuration, but it seems there is a RabbitAutoConfiguration class that implies it is a SB autoconfig class, but in actual fact it is a normal SB config class.

Is there a cleaner way to disable the Cloud Bus that also prevents RabbitMQ from starting?

Jay Guidos
  • 151
  • 9
  • The disabling of bus does not disable the rabbitmq binder for spring cloud stream. I'm unsure if there is a way to do that with properties. – spencergibb Aug 05 '20 at 16:35
  • Ok then, can you suggest a way to do this programatically? I could add some conditional configuration of my own. – Jay Guidos Aug 05 '20 at 16:58
  • There is a [TestBinder available](https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.2.0.M1/spring-cloud-stream.html#_testing) that seems to do the trick. If I include it as per the instructions in the link then the rabbitMQ binder is ignored. I will try the excluding autoconfig trick as a profile, since I have to carry the test binder into the actual deployed docker container for running integration tests. – Jay Guidos Aug 05 '20 at 18:01
  • Yes, including an autoconfig exclusion that is triggered when doing a 'real' production deployment (where RabbitMQ is available) works. I kind of like this, I can achieve my goals using nothing but SpringBoot config, thanks to TestBinder – Jay Guidos Aug 05 '20 at 18:25

1 Answers1

0

You just need to include the spring-cloud-stream-test-support jar in your test scope. This jar includes binders that will override and replace the default binders. These test binders will not actually connect to the resources in the background.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-stream-test-support</artifactId>
    <version>${spring.cloud.stream.version}</version>
    <scope>test</scope>
</dependency>
SpaceGerbil
  • 224
  • 4
  • 14