【问题标题】:How to dynamically add queue to exchange in Spring Integration如何在 Spring Integration 中动态添加队列以进行交换
【发布时间】:2018-03-24 11:20:57
【问题描述】:

我在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
 }

【问题讨论】:

    标签: java spring spring-boot spring-integration spring-integration-amqp


    【解决方案1】:

    使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-01
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 2014-07-28
      相关资源
      最近更新 更多