![](/img/trans.png)
[英]RabbitMQ + Spring Integration: Message conversion from queue bound to a topic exchange
[英]How to dynamically add queue to exchange in Spring Integration
我在integrationcontext.xml中进行了以下交换
<!-- rabbit exchanges, queues, and bindings used by this app -->
<rabbit:topic-exchange name="newPaymentEventsExchange" auto-delete="false" durable="true">
<rabbit:bindings>
</rabbit:bindings>
</rabbit:topic-exchange>
我需要能够根据数据库中以下对象的channelName值动态地向交换添加队列,我也应该能够在有人添加新频道时更新:
public class Channel {
private Long channelId;
private String tenantId;
private String channelName;
------
//Getters & setters
}
使用AmqpAdmin
执行此类操作:
/**
* Declare the given queue.
* @param queue the queue to declare.
* @return the name of the queue.
*/
String declareQueue(Queue queue);
/**
* Declare a binding of a queue to an exchange.
* @param binding a description of the binding to declare.
*/
void declareBinding(Binding binding);
为方便起见,您可以考虑使用QueueBuilder
和BindingBuilder
:
QueueBuilder.nonDurable("foo")
.autoDelete()
.exclusive()
.withArgument("foo", "bar")
.build()
...
BindingBuilder.bind(
marketDataQueue()).to(marketDataExchange()).with(marketDataRoutingKey)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.