Govinda Sakhare
Govinda Sakhare

Reputation: 5749

Spring Cloud Stream is creating exchange on Consumer service startup

I have two microservices Student and Teacher

in Student microservice I am creating a MessageSink for exchange XYZ

@Input("XYZ")
SubscribableChannel xyz();

and in Teacher microservice I am configuring exchange XYZ as a fanout

application.properties

 spring.cloud.stream.rabbit.bindings.XYZ.producer.exchangeType=fanout
 spring.cloud.stream.bindings.XYZ.contentType=application/json

But problem I am facing here is Student service is starting before Teacher service and it is creating XYZ exchange with type Topic and then Teacher service starting is giving me following error:

amqp.rabbit.core.RabbitAdmin - Failed to declare exchange: Exchange [name=XYZ, type=fanout, durable=true, autoDelete=false, internal=false, arguments={}], continuing... com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'XYZ' in vhost '/': received 'fanout' but current is 'topic', class-id=40, method-id=10)

so is there any configuration to change the exchangeType or delete existing exchange and create new exchange or set exchangeType in @Input ?

Upvotes: 0

Views: 1012

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

You can consider to disable exchange creation there via configuration properties:

declareExchange

    Whether to declare the exchange for the destination.

    Default: true.

https://docs.spring.io/spring-cloud-stream/docs/Elmhurst.M3/reference/htmlsingle/#_rabbitmq_consumer_properties

Upvotes: 2

Related Questions