我已经阅读了spring cloud stream绑定器参考文档,其中提到了使用@RabbitListener进行DLQ处理。https://docs.spring.io/spring-cloud-stream-binder-rabbit/docs/3.0.10.RELEASE/reference/html/spring-cloud-stream-binder-rabbit.html#rabbit-dlq-processing
我们能否通过Spring云函数实现同样的目标,就像我们可以为消费者做同样的事情一样?喜欢
@Bean
public Consumer<Message> dlqprocess(DLQProcess dlqprocess) {
return t -> dlqprocess.do(t);
}我不确定我们是否能做到这一点。如果这是允许的,我们必须做的其他配置是什么?
发布于 2021-09-22 10:31:13
如果您的目标是重新排队失败的消息,则该函数可以像docs中描述的那样抛出异常。
此外,如果需要对发送和重新排队的消息进行更细粒度的控制,可以使用StreamBrdidge。这里您需要在配置文件中显式定义DLQ绑定:
spring.cloud.stream.bindings.myDlq-out-0.destination=DLX
spring.cloud.stream.rabbit.bindings.myDlq-out-0.producer.exchangeType=direct
spring.cloud.stream.rabbit.bindings.myDlq-out-0.producer.routingKeyExpression='myDestination.myGroup'
spring.cloud.stream.source=myDlq最后,该函数控制是否发送和重新排队消息:
@Bean
public Consumer<Message> process(StreamBridge streamBridge) {
return t -> {
// ....
if(republish) streamBridge.send("myDlq-out-0", t);
if(sendToDestination) streamBridge.send("myDestination-out-0", t);
// ....
};
}https://stackoverflow.com/questions/69218264
复制相似问题