【发布时间】:2015-12-07 05:07:12
【问题描述】:
从 RabbitMQ 连接规范列表到发布订阅通道上的一系列消费者的正确方法是什么?
也就是说,我的兔子配置如下:
rabbits:
- hostname: blahblah
vhost: blahlbah
username: blahlbah
password: blahlbalh
exchange: blahblah
- hostname: blahblah1
vhost: blahlbah1
username: blahlbah1
password: blahlbalh1
exchange: blahblah1
...
我将这些编组为@NestedConfigurationProperty List<RabbitConfiguration>。我可以编写一个@Bean 方法,从其中一个List<RabbitConfiguration> 中获取AmqpTemplate,如下所示:
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AmqpTemplate amqpTemplate(RabbitConfiguration rabbitConfiguration) {
...
}
然后我基本上可以将其映射到IntegrationFlow:
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public IntegrationFlow integrationFlow(AmqpTemplate amqpTemplate) {
return IntegrationFlows.from(inboundPubSubChannel()).handle(Amqp.outboundAdapter(amqpTemplate)).get();
}
但是,对于 List<RabbitConfiguration> 执行此操作并让 Spring 处理生成的 List<IntegrationFlow> 的正确方法是什么?当然不只是:
@Bean
public List<IntegrationFlow> integrationFlows(List<RabbitConfiguration> rabbitConfigurations) {
return rabbitConfigurations.stream()
.map(this::amqpTemplate)
.map(this::integrationFlow)
.collect(toList())
}
【问题讨论】:
标签: java spring rabbitmq spring-integration spring-java-config