gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:09 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com