chore: 补充后端核心模块的中文注释

This commit is contained in:
2026-07-15 11:54:01 +08:00
parent e3c68dd6d3
commit ffd9b0c8f0
12 changed files with 70 additions and 39 deletions

View File

@@ -32,13 +32,13 @@ func (w *LikeWorker) Run(ctx context.Context) error {
}
deliveries, err := w.ch.Consume(
w.queue,
"",
false,
false,
false,
false,
nil,
w.queue, // 队列名
"", // 消费者标签,空代表让 RabbitMQ 自动生成一个唯一的标签
false, // autoAck = false 采用手动确认模式
false, // exclusive = false 允许多个消费者同时消费同一个队列
false, // noLocal = false 允许消费者接收自己发送的消息
false, // noWait = false 阻塞等待 RabbitMQ 的响应
nil, // args
)
if err != nil {
return err

View File

@@ -14,6 +14,7 @@ import (
"gorm.io/gorm"
)
// 轮询器,轮询数据库中的 outbox 表,获取待投递的消息,投递到 MQ 中
func StartOutboxPoller(db *gorm.DB, tmq *rabbitmq.TimelineMQ) {
if db == nil || tmq == nil {
log.Printf("Outbox poller disabled: timeline mq is not initialized")
@@ -46,6 +47,7 @@ func StartOutboxPoller(db *gorm.DB, tmq *rabbitmq.TimelineMQ) {
}()
}
// 消费者,消费 MQ 中的消息,写入 Redis 的 Zset 中
func StartConsumer(tmq *rabbitmq.TimelineMQ, queueName string, redisClient *rediscache.Client, rmq *rabbitmq.RabbitMQ) {
if tmq == nil || rmq == nil || rmq.Conn == nil {
log.Printf("Timeline consumer disabled: rabbitmq is not initialized")
@@ -66,6 +68,8 @@ func StartConsumer(tmq *rabbitmq.TimelineMQ, queueName string, redisClient *redi
continue
}
// 设置当前 Channel 的 QoSQuality of Service参数控制消息的预取数量和大小
// prefetch count = 10 一次最多取10个消息, prefetch size = 0 不限制预取的字节大小, global = false Qos 设置只对当前 Channel 生效
if err := ch.Qos(10, 0, false); err != nil {
log.Printf("Timeline consumer: QoS 设置失败: %v", err)
}