feat(mq): 声明停泊链路与各队列独立的重试参数

为"处理失败的消息有去处"准备 broker 侧契约,本提交只做声明,不改变消费行为。

停泊链路(declareParking):DLX 交换机 dlx.events + 唯一停泊队列 failed.events
+ parked.# 绑定。形状与旧的 <queue>.dlx 相反——旧实现每个业务队列建一个
<queue>.dlx 且都以 "#" 绑定同一个交换机,一旦真的产生死信,topic 会把它扇出成
N 份;停泊队列只有一个、绑定一次,一条消息只会落一份。

重试参数(RetryArgs / RetryQueueArgs):x-dead-letter-exchange 指向本队列专属的
retry.events.<Q>,重试队列 <Q>.retry 用队列级 TTL 延迟后经默认交换机按队列名
精确回源。每队列独立是必需的:like.events 与 notification.like 共享交换机且
路由键重叠,共用重试入口会把消息重投到错误的队列。

RetryArgs 刻意不设 x-dead-letter-routing-key,使第 1 次被拒绝时保留原路由键;
从第 2 次起路由键是队列名(回源那步写死),这一点由 RetryArgs 的注释和
TestRetryArgs_OnlyOverridesDeadLetterExchange 共同钉住。

DeclareTopologies 先声明停泊链路再声明业务拓扑,且停泊链路声明失败会终止整轮
重放(而不是仅告警):业务队列的 DLX 指向一个不存在的交换机时,broker 会丢弃
被拒绝的消息,而 worker 以为已经处理完。既有顺序测试相应改为先断言停泊前缀。

同时补上 ParkedInfo/ParseParkedInfo/EventIDOf 与新的线缆名常量,
新增 constants_test.go 的钉值断言。
This commit is contained in:
2026-10-30 13:12:38 +08:00
parent 5f250fa7cd
commit 4e412a2c84
5 changed files with 388 additions and 6 deletions

View File

@@ -45,6 +45,15 @@ func TestTopologyConstants_WireNamesAreStable(t *testing.T) {
{"NotificationLikeQueue", NotificationLikeQueue, "notification.like"},
{"NotificationCommentQueue", NotificationCommentQueue, "notification.comment"},
{"NotificationSocialQueue", NotificationSocialQueue, "notification.social"},
// 停泊链路(批次 0)。failed.events 是运维真正会去查的队列名,
// dlx.events 沿用了改造前就存在的名字,因此改名同样等同于一次迁移。
{"DLXExchange", DLXExchange, "dlx.events"},
{"ParkedQueue", ParkedQueue, "failed.events"},
{"ParkedKeyPrefix", ParkedKeyPrefix, "parked."},
// 重试链路(批次 2 启用,但名字属于线缆契约,与常量同批锁定)。
{"RetryExchangePrefix", RetryExchangePrefix, "retry.events."},
{"RetryQueueSuffix", RetryQueueSuffix, ".retry"},
}
for _, c := range cases {
if c.got != c.want {