第32篇 rabbitmq RecordedExchange重试和恢复源码分析

本文深入探讨了RabbitMQ中的ConnectionParams连接参数,重点讲解了RecordedXXX和RetryXXX相关类,如RecordedEntity、RecordedQueueBinding、RecordedExchange等的恢复机制和RetryContext、RetryResult的使用。这些类主要用于在异常情况下恢复RabbitMQ的实体状态和执行重试操作,确保消息传递的可靠性。

继续第31篇,说到ConnectionParams 连接参数,主要超时时间,执行器,处理器,监听器,还遗留两个TODO,就是恢复RecordedXXXX RetryXXX ,哪些记录需要恢复和重试恢复动作结果

1、RecordedXXX

  • 如下是类图

image-20210709152858044

  • 主要是Binding 、Queue、Exchange、Consumer ,我们一个一个类来看

1.1、RecordedEntity

  • 只有一个成员变量 AutocoveringChannel channel (可恢复通道)太大这个类后面去盘它

1.2、RecordedBinding

成员变量默认值描述
String source
String destination目标
String routingKey路由key
Map<String, Object> arguments其他参数
  • 重写了equals 和hashCode方法
  • 增加一个recover的抽象方法

1.3、RecordedQueueBinding

  • 队列绑定
  • 只有一个实现recover方法,也就利用父类的参数进行恢复操作
方法名描述
recover()获取代理通道对象执行绑定方法
  • this.channel.getDelegate().queueBind(this.getDestination(), this.getSource(), this.routingKey, this.arguments);

1.4、RecordedExchangeBinding

  • 交换绑定
  • 只有一个实现recover方法,也就利用父类的参数进行恢复操作
方法名描述
recover()获取代理通道对象执行绑定方法
  • this.channel.getDelegate().exchangeBind(this.destination, this.source, this.routingKey, this.arguments);
    

1.5、RecordedNamedEntity

  • 只有一个成员变量 name属性

1.6、RecordedExchange

  • Exchange记录
成员变量默认值描述
boolean durable持久
boolean autoDelete字段删除
Map<String, Object> arguments参数
String type类型
  •     this.channel.getDelegate().exchangeDeclare(this.name, this.type, this.durable, this.autoDelete, this.arguments);
      
    

1.7、RecordedQueue

  • Queue记录
成员变量默认值描述
boolean durable持久
boolean autoDelete字段删除
Map<String, Object> arguments参数
boolean exclusive不包括
boolean serverNamed服务端的名字
  • this.name = this.channel.getDelegate().queueDeclare(this.getNameToUseForRecovery(),
                                                        this.durable,
                                                        this.exclusive,
                                                        this.autoDelete,
                                                        this.arguments).getQueue();
    

1.8、RecordedConsumer

  • 恢复消费者
成员变量默认值描述
String queue队列
String consumerTag消费者标签
Consumer consumer消费者
boolean exclusive不包括
boolean autoAck自动ack
Map<String, Object> argument其他参数
  • recover方法

  •     this.consumerTag = this.channel.getDelegate().basicConsume(this.queue, this.autoAck, this.consumerTag, false, this.exclusive, this.arguments, this.consumer);
      
    

2 、RetryXXX

2.1、RetryContext

  • 重试上下文信息(重试需要准备环境和参数)
2.1.1、成员变量
成员变量默认值描述
RecordedEntity entity记录恢复实体
Exception exception异常
AutorecoveringConnection connection恢复连接对象
2.1.2、方法
方法名描述
connection()恢复连接对象
exception()异常
entity()记录实体类
exchange()将entity强转RecordedExchange
binding()将entity强转 RecordedBinding
consumer()将entity强转 RecordedConsumer

2.2、RetryResult

成员变量默认值描述
RecordedEntity recordedEntity记录恢复实体
Object result重试的结果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值