我在 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 值动态向交换器添加队列,而且我应该能够在以下时间进行更新有人添加了新 channel :
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)
关于java - 如何在 Spring Integration 中动态添加队列以进行交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710990/