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

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

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

为方便起见,您可以考虑使用 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

关于java - 如何在 Spring Integration 中动态添加队列以进行交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710990/

相关文章:

javascript - Spring Boot 应用程序 JS 和 CSS 未在独立服务器中绑定(bind)(Apache Tomcat 版本 9.0)

java - 使用 Logback RollingFileAppender 时,有没有办法使用默认的 Spring Boot "/actuator/logfile"端点?

java - 如何在 Eclipse 中指定测试类路径

java - 类的模拟在 Spock 测试用例中不起作用

java - 无法在 Spring MVC Controller 测试中模拟服务类

spring - STS Spring Boot 仪表板无法识别成功启动

java - jOOQ不想生成数据库资源

java - 将java复选框值插入sql

java - 将新主机添加到 apache ignite 数据网格

java - Spring JPA 不在更新时验证 bean