Spring Cloud Stream 正在消费者服务启动时创建交换

Spring Cloud Stream is creating exchange on Consumer service startup

我有两个微服务 StudentTeacher

Student 微服务中我正在创建一个 MessageSink 用于交换 XYZ

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

并且在 Teacher 微服务中,我将交换 XYZ 配置为 fanout

application.properties

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

但我在这里面临的问题是 Student 服务在 Teacher 服务之前启动,它正在创建类型为 TopicXYZ exchange,然后是 Teacher服务启动时出现以下错误:

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)

那么是否有任何配置可以更改 exchangeType 或删除现有的 exchange 并创建新的 exchange 或在 @Input 中设置 exchangeType

您可以考虑通过配置属性禁用交换创建:

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