以编程方式禁用 RabbitAutoConfiguration
在 Spring Boot (1.2.2) 中是否有禁用 RabbitAutoConfiguration 的编程(基于属性)方法.
Is there a programmatic(properties based) way of disabling RabbitAutoConfiguration in spring boot (1.2.2).
看起来 spring.rabbitmq.dynamic=false 只禁用了 AmqpAdmin 而不是连接工厂等.
Looks like spring.rabbitmq.dynamic=false disables just the AmqpAdmin but not the connection factory etc.
我们想要一个模型,其中应用程序属性可能来自 spring 云配置(包括控制总线)或通过 -D jvm args.这个决定是在部署时做出的.当属性来自 -D jvm args 时,我们禁用了 spring cloud 配置客户端,但 rabbit 不断抛出异常,例如:
We want a model where app properties might be sourced from spring cloud config (includes control bus) or via -D jvm args. This decision is made at deployment time. When properties are sourced from -D jvm args, we disable the spring cloud config client but rabbit keeps throwing exceptions such as :
[org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - [Consumer 引发异常,如果连接工厂支持,处理可以重新启动ts它.异常摘要:org.springframework.amqp.AmqpConnectException:java.net.ConnectException:连接被拒绝:连接]
[org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - [Co nsumer raised exception, processing can restart if the connection factory suppor ts it. Exception summary: org.springframework.amqp.AmqpConnectException: java.ne t.ConnectException: Connection refused: connect]
首先你需要从你的应用中排除 RabbitAutonfiguration
First you need to exclude RabbitAutonfiguration from your app
@EnableAutoConfiguration(exclude=RabbitAutoConfiguration.class)
然后你可以根据这样的一些属性导入它
Then you can import it based on some property like this
@Configuration
@ConditionalOnProperty(name="myproperty",havingValue="valuetocheck",matchIfMissing=false)
@Import(RabbitAutoConfiguration.class)
class RabbitOnConditionalConfiguration{
}