繁体   English   中英

如何在Spring Integration中动态添加队列进行交换

[英]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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM