refactor(rabbitmq): social.events 只承载通知
All checks were successful
CI/CD / Verify and Deploy (push) Successful in 3m23s
All checks were successful
CI/CD / Verify and Deploy (push) Successful in 3m23s
删除没有消费者的 SocialQueue 队列与 social.unfollow 路由键。SocialMQ 改登记 notification.social。 因此关注事件只走通知链路。social.events 不再是写库副本。 文档同步:解决方案、问题报告、写路径幂等、死信队列、项目设计。 验证:go vet ./... 通过,go test -count=1 ./... 全绿。
This commit is contained in:
@@ -13,12 +13,9 @@ type SocialMQ struct {
|
||||
|
||||
// 拓扑常量导出:见 likeMQ.go 中的说明。
|
||||
const (
|
||||
SocialExchange = "social.events"
|
||||
SocialQueue = "social.events"
|
||||
SocialBindingKey = "social.*"
|
||||
SocialExchange = "social.events"
|
||||
|
||||
SocialFollowRK = "social.follow"
|
||||
SocialUnfollowRK = "social.unfollow"
|
||||
SocialFollowRK = "social.follow"
|
||||
)
|
||||
|
||||
type SocialEvent struct {
|
||||
@@ -29,11 +26,12 @@ type SocialEvent struct {
|
||||
OccurredAt time.Time `json:"occurred_at"`
|
||||
}
|
||||
|
||||
// NewSocialMQ 只登记关注通知的落点:服务层已先写库,事件不再承担写库职责。
|
||||
func NewSocialMQ(base *RabbitMQ) (*SocialMQ, error) {
|
||||
if base == nil {
|
||||
return nil, errors.New("rabbitmq base is nil")
|
||||
}
|
||||
base.RegisterTopology(Topology{Exchange: SocialExchange, Queue: SocialQueue, BindingKey: SocialBindingKey})
|
||||
base.RegisterTopology(Topology{Exchange: SocialExchange, Queue: NotificationSocialQueue, BindingKey: SocialFollowRK})
|
||||
return &SocialMQ{mgr: base}, nil
|
||||
}
|
||||
|
||||
@@ -41,10 +39,6 @@ func (s *SocialMQ) Follow(ctx context.Context, followerID, vloggerID uint) error
|
||||
return s.publish(ctx, "follow", SocialFollowRK, followerID, vloggerID)
|
||||
}
|
||||
|
||||
func (s *SocialMQ) UnFollow(ctx context.Context, followerID, vloggerID uint) error {
|
||||
return s.publish(ctx, "unfollow", SocialUnfollowRK, followerID, vloggerID)
|
||||
}
|
||||
|
||||
func (s *SocialMQ) publish(ctx context.Context, action, routingKey string, followerID, vloggerID uint) error {
|
||||
if s == nil || s.mgr == nil {
|
||||
return errors.New("social mq is not initialized")
|
||||
|
||||
Reference in New Issue
Block a user