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

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

被折叠的 条评论
为什么被折叠?



