加载 RabbitMQ 或 IBM MQ 配置在基于环境值的 Spring Boot 中。

huangapple go评论91阅读模式
英文:

Load Rabbit or IBM mq config in Spring Boot based on en value

问题

以下是您要翻译的内容:

用例:我想根据代理商值(环境变量)加载IBM或RabbitMQ配置。我的监听器(消息驱动的POJO)在单独工作。这是必需的,因为我的开发和测试在Rabbit上运行,而QA和生产在IBM上运行。

应用程序:Spring Boot

我正在考虑根据环境加载属性。

Appconfig.java

@Configuration
@ConfigurationProperties(classpath: application-${spring.profile.active}-{config-broker}.properties)

// 代理商的值可以是IBM、Rabbit或None

public MQQueueConnectionFactory mqQueueConnectionFactory(){
..
}

问题:如何确保我只加载IBM和Rabbit的配置,而不加载两者。

是否有一种方法只加载一个应用程序配置类和消息监听器。

附注:使用单个配置(IBM/Rabbit),我能够无问题地加载和启动我的监听器。

英文:

Use case : I want to load IBM or RabbitMq configuration based on a broker value (env variable). My listeners (Message Driven POJO) are working individually. This is required because my DeV and Test runs on Rabbit and QA and Prod Runs on IBM.

App: Spring Boot

I am thinking of loading the properties based on env.

Appconfig.java

@Configuration
    @ConfigurationProperties(classpath: application-${spring.profile.active}-{config-broker}.properties)

//Broker value can be IBM, Rabbit or None

public MQQueueConnectionFactory mqQueueConnectionFactory(){
..
}

Question: How do I make sure I load only IBM and Rabbit config and not load both.

Is there a way to load only one App config class and Message Listeners.

PS : with single config(ibm/rabbit), I am able to load and start my listener without any issues.

答案1

得分: 1

其他人已经说过,你可能应该更改你的设置并在开发中使用IBM MQ高级版。

不过,为了回答你的问题,你可以简单地在你的 @Beans 或整个 @Configuration 类上使用 @ConditionalOnProperty 进行注解,就像这样:

@ConditionalOnProperty(name = "spring.profile.active", havingValue = "dev")
@Bean
// RabbitMQ...
英文:

As the others have said, you should likely change your setup and use IBM MQ Advanced for development.

To answer your question, though, you could simply annotate your @Beans or whole @Configuration classes with @ConditionalOnProperty, like

@ConditionalOnProperty(name = "spring.profile.active", havingValue = "dev")
@Bean
// RabbitMQ...

huangapple
  • 本文由 发表于 2020年4月8日 00:39:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/61084985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定