Spring 集成中如何动态添加队列交换

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);

您可以考虑使用 QueueBuilderBindingBuilder 以方便使用:

QueueBuilder.nonDurable("foo")
    .autoDelete()
    .exclusive()
    .withArgument("foo", "bar")
    .build()
...
BindingBuilder.bind(
            marketDataQueue()).to(marketDataExchange()).with(marketDataRoutingKey)

https://docs.spring.io/spring-amqp/docs/2.0.0.RELEASE/reference/html/_reference.html#broker-configuration