SpringCloud 整合在一起
2023-11-29 16:03 更新
以下配置创建一个交换myDestination
,其中队列myDestination.consumerGroup
与通配符路由键#
绑定到主题交换:
--- spring.cloud.stream.bindings.input.destination=myDestination spring.cloud.stream.bindings.input.group=consumerGroup #disable binder retries spring.cloud.stream.bindings.input.consumer.max-attempts=1 #dlx/dlq setup spring.cloud.stream.rabbit.bindings.input.consumer.auto-bind-dlq=true spring.cloud.stream.rabbit.bindings.input.consumer.dlq-ttl=5000 spring.cloud.stream.rabbit.bindings.input.consumer.dlq-dead-letter-exchange= ---
此配置将创建一个绑定到直接交换(DLX
)的DLQ,其路由密钥为myDestination.consumerGroup
。当邮件被拒绝时,它们将被路由到DLQ。5秒后,该消息到期,并通过使用队列名称作为路由键将其路由到原始队列,如以下示例所示:
Spring Boot应用程序。
@SpringBootApplication @EnableBinding(Sink.class) public class XDeathApplication { public static void main(String[] args) { SpringApplication.run(XDeathApplication.class, args); } @StreamListener(Sink.INPUT) public void listen(String in, @Header(name = "x-death", required = false) Map<?,?> death) { if (death != null && death.get("count").equals(3L)) { // giving up - don't send to DLX throw new ImmediateAcknowledgeAmqpException("Failed after 4 attempts"); } throw new AmqpRejectAndDontRequeueException("failed"); } }
请注意,x-death
标头中的count属性是Long
。
以上内容是否对您有帮助:
更多建议: