首页 > 其他分享 >Spring Cloud Stream RabbitMQ消费消息失败

Spring Cloud Stream RabbitMQ消费消息失败

时间:2022-10-30 18:38:09浏览次数:37  
标签:Stream Spring destination RabbitMQ content application json hking type


丢弃消息

这种场景生产环境应该不怎么用。

入死信队列

cloud:
stream:
bindings:
hking:
destination: hking
content-type: application/json
hking-input:
destination: hking
group: hking
content-type: application/json
rabbit:
bindings:
hking-input:
consumer:
auto-bind-dlq: true

重新入原队列

cloud:
stream:
bindings:
hking:
destination: hking
content-type: application/json
hking-input:
destination: hking
group: hking
content-type: application/json
consumer:
max-attempts: 1
rabbit:
bindings:
hking-input:
consumer:
republish-to-dlq: false
requeue-rejected: true

这样配置的话,消息消费失败,重回原队列,程序这边一直出错的话,会一直接收到这个消息。max-attempts=1就是关闭重试,republish-to-dlq=false是不往死信队列里面转发,在这种情况下,设置requeue-rejected=true,消息会重新回到他出来的消息队列。

应用记录消息日志

@StreamListener(value = HkingInput.QUEUE, condition = "headers['event']=='String'")
public void processMyMessage3(User2 message) {
throw new RuntimeException();
}


/**
* 消息消费失败的降级处理逻辑
*
* @param message
*/
@ServiceActivator(inputChannel = "<destination>.<group>.errors")
public void error(Message<?> message) {
System.out.println(message);
log.info("Message consumer failed, call fallback!");
}

重试和回退机制

Retry Template and retryBackoff。

cloud:
stream:
bindings:
hking:
destination: hking
content-type: application/json
hking-input:
destination: hking
group: hking
content-type: application/json
consumer:
max-attempts: 1

一条消息尝试被一个StreamListener注解的方法多处理几次。max-attempts设置为1就是关闭重试。重试可以设置重试的次数,回退机制可以设置重试的间隔策略。


标签:Stream,Spring,destination,RabbitMQ,content,application,json,hking,type
From: https://blog.51cto.com/xichenguan/5807686

相关文章

  • springboot~写一个从excel读取json到List<Map>的方法
    excel读出来的json,它是一个字符串,不是标准json,所以需要对字符串字段进行解析复杂的excel如图通过poi解析json,通过jackson完成对字段的解析publicstaticList<Map<String,O......
  • SSM框架(spring+springmvc+mybatis)+Mysql实现的社区物业管理系统(功能包含分角色,报修
    (博客目录)SSM框架(spring+springmvc+mybatis)+Mysql实现的社区物业管理系统本系统为了解决线下物业管理小区的冗余繁杂的难题,通过整合业主和物业,将平时的业务在线化,节省......
  • 十四,SpringBoot-整合Quartz
     Quartz是一个任务调度框架,在以前我们使用它的时候都是xml配置的方式,在spingboot中只需要几个注解就可以轻松搞定。主要用到以下几个注解:1.@Scheduled可以理解成触发器2.......
  • SSM框架(spring+springmvc+mybatis)+layui+Mysql实现的停车位租赁系统(功能包含注册登
    (博客目录)SSM框架(spring+springmvc+mybatis)+layui+Mysql实现的停车位租赁系统本系统为了解决停车位租赁不透明的难题,提供了一个连接租客和车位主的一个平台,通过不同角......
  • SSM框架(spring+springmvc+mybatis)+layui+Mysql实现的医院在线预约挂号管理系统(功能
    (博客目录)SSM框架(spring+springmvc+mybatis)+layui+Mysql实现的医院在线预约挂号管理系统本系统为了患者线下预约挂号难的问题,打通医院和患者之间的一个渠道,通过在线透......
  • SpringBoot 阶段测试 1
    SpringBoot阶段测试1目录SpringBoot阶段测试11、使用JDK8新语法完成下列集合练习:1.1List中有1,2,3,4,5,6,7,8,9几个元素要求;(1)将奇、偶数分别汇聚成一个List(2)分别求......
  • Mybatis整合Spring
    一、整合思路。1、SqlSessionFactory对象交给Spring容器管理。2、传统dao的开发方式中应该从Spring容器中获取sqlSession对象。3、Mapper代理形式中,应该从Spring容器中......
  • springboot源码剖析(四) 上下文启动
    概念      springboot在启动流程中最重要的事情便是加载启动spring组件,比如加载IOC容器,启动springMVC等。实现原理  使用AnnotationConfig......
  • springboot源码剖析(三) 环境配置
    概念      springboot在启动流程中会把环境配置都加载进应用当中。实现原理     使用环境配置器用来加载和解析所有配置文件。配置文件......
  • springboot2
    学习文档:https://blog.csdn.net/ttxbgjj/article/details/122881011---尚硅谷课程笔记https://www.yuque.com/atguigu/springboot  ---尚硅谷官网文档学习视频:https:......