feat(worker): 五个消费者改用 ConsumeLoop 分派重试与停泊

每个 worker 的 Run 只保留参数校验。消费循环统一由 rabbitmq.ConsumeLoop 驱动。
因此重试、停泊、Ack 的规则只有一份实现。

坏消息一律标记 rabbitmq.Permanent。因此解析失败与未知 action 立即停泊。
未知 action 不再被静默 Ack 丢弃。

notification worker 改按队列与 body.action 分派。重试回源会把 routing key
改写成队列名。因此按 routing key 判断会让第二次投递立即停泊。

验证:go test -count=1 ./... 全绿
This commit is contained in:
2026-10-30 15:20:15 +08:00
parent 03d4301020
commit 49fc17c445
10 changed files with 290 additions and 369 deletions

View File

@@ -72,7 +72,7 @@ func seedCommentVideo(t *testing.T, db *gorm.DB) *video.Video {
func TestCommentWorker_ApplyPublish_DuplicateEventWritesOneRow(t *testing.T) {
db := newCommentWorkerTestDB(t)
v := seedCommentVideo(t, db)
w := NewCommentWorker(nil, video.NewCommentRepository(db), video.NewVideoRepository(db), "comment.events")
w := NewCommentWorker(nil, nil, video.NewCommentRepository(db), video.NewVideoRepository(db), "comment.events")
evt := &rabbitmq.CommentEvent{
EventID: "evt-comment-1",
Action: "publish",
@@ -110,7 +110,7 @@ func TestCommentWorker_ApplyPublish_DuplicateEventWritesOneRow(t *testing.T) {
func TestCommentWorker_ApplyPublish_EmptyEventIDStillWrites(t *testing.T) {
db := newCommentWorkerTestDB(t)
v := seedCommentVideo(t, db)
w := NewCommentWorker(nil, video.NewCommentRepository(db), video.NewVideoRepository(db), "comment.events")
w := NewCommentWorker(nil, nil, video.NewCommentRepository(db), video.NewVideoRepository(db), "comment.events")
evt := &rabbitmq.CommentEvent{
Action: "publish",
@@ -137,7 +137,7 @@ func TestCommentWorker_ApplyDelete_DuplicateIsNoop(t *testing.T) {
db := newCommentWorkerTestDB(t)
v := seedCommentVideo(t, db)
repo := video.NewCommentRepository(db)
w := NewCommentWorker(nil, repo, video.NewVideoRepository(db), "comment.events")
w := NewCommentWorker(nil, nil, repo, video.NewVideoRepository(db), "comment.events")
c := &video.Comment{Username: "alice", VideoID: v.ID, AuthorID: 1, Content: "x"}
if _, err := repo.CreateIdempotentWithPopularity(context.Background(), c, 0); err != nil {