Disabling Spring Cloud Bus still ends up starting RabbitMQ

1.2k views Asked by At

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?

1

There are 1 answers

0
SpaceGerbil On

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>