【发布时间】:2020-01-30 20:39:55
【问题描述】:
我需要将队列绑定到主题交换,但是:
- 仅当主题存在时
- 如果主题存在,请使用现有设置(例如持久、自动删除等)
原因是,我需要一个 3rd 方应用程序来使用他们想要使用的任何设置来创建交换,我不想修改主题设置。
我通过阅读 RabbitMQ Spring AMQP 教程将下面的代码放在一起。它可以工作,但如果不存在,则会创建一个交换。
@Configuration
public class BeanConfiguration {
@Bean
public TopicExchange topic() {
return new TopicExchange("MyTopicExchange", true, false);
}
@Bean
public Queue queue() {
return QueueBuilder.durable("MyQueue").build();
}
@Bean
public Binding binding(TopicExchange topicExchange, Queue queue) {
return BindingBuilder.bind(queue).to(topicExchange).with("purchases.*");
}
}
【问题讨论】:
标签: spring spring-amqp spring-rabbit