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

时间:2018-02-06 19:59:35

标签: spring microservices spring-cloud-stream spring-rabbitmq

我有两个微服务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服务之前启动的,它正在创建XYZ exchange类型Topic,然后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中创建新exchangeType或设置@Input

1 个答案:

答案 0 :(得分:2)

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

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