![](/img/trans.png)
[英]Programmatically declare bindings in Spring Cloud Stream (RabbitMQ)?
[英]How to Shutdown/Stop RabbitMQ queue of Spring Cloud stream bindings
我想阻止 rabbitmq 中的消费者在点击端点 /prepare-for-shutdown 时从 spring 云 stream 绑定创建队列。 请在下面找到配置,
在 pom.xml 中添加了依赖项
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
应用程序.yml:
spring:
cloud:
stream:
bindings:
produceChannel:
binder: rabbit
content-type: application/json
destination: internal-exchange
consumeChannel:
binder: rabbit
content-type: application/json
destination: internal-exchange
group: small-queue
rabbit:
bindings:
consumeChannel:
consumer:
autoBindDlq: true
durableSubscription: true
requeueRejected: false
republishToDlq: true
bindingRoutingKey: admin
produceChannel:
producer:
routingKeyExpression: '"admin"'
样品.java
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel;
public interface Sample{
@Input("consumeChannel")
SubscribableChannel consumeChannel();
@Output("produceChannel")
SubscribableChannel produceChannel();
}
使用 Spring Cloud 的 @StreamLinster 和 @EnableBinding 抽象实现了与 RabbitMQ 的集成,如下所示:
@EnableBinding(Sample.class)
@StreamListener("consumeChannel")
public void sampleMessage(String message) {
// code
}
期待以编程方式停止 RabbitMQ 队列的消费者。 提前致谢
我通过调用执行器端点'/actuator/bindings'分析了为什么会得到空值的问题
当命中执行器绑定端点时,它会调用 BindingsEndpoint.class 中的方法gatherInputBindings()。
在 BindingsEndpoint.java 中,从 inputBindingLifecycle 获取绑定值
(Collection<Binding<?>>) new DirectFieldAccessor(inputBindingLifecycle).getPropertyValue("inputBindings");
在以下方法中,将空绑定列表设置为 inputBindings
在 InputBindingLifecycle.java 中,
void doStartWithBindable(Bindable bindable) {
this.inputBindings = bindable.createAndBindInputs(bindingService);
}
在 Bindable.java 中,
default Collection<Binding<Object>> createAndBindInputs(BindingService adapter) {
return Collections.<Binding<Object>>emptyList();
}
请建议我解决这些问题是否需要更改任何依赖项或任何代码配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.