Files
im_manager/server/internal/queues/im_admin_command_result.go
T

53 lines
1.4 KiB
Go

// Package queues
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2026 HotGo
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queues
import (
"context"
"encoding/json"
"hotgo/internal/consts"
"hotgo/internal/library/imkafka"
"hotgo/internal/library/queue"
)
func init() {
queue.RegisterConsumer(ImAdminCommandResult)
}
var ImAdminCommandResult = &qImAdminCommandResult{}
type qImAdminCommandResult struct{}
func (q *qImAdminCommandResult) GetTopic() string {
return consts.QueueImAdminCommandResultTopic
}
func (q *qImAdminCommandResult) Handle(ctx context.Context, mqMsg queue.MqMsg) (err error) {
var envelope imkafka.Envelope
if err = json.Unmarshal(mqMsg.Body, &envelope); err == nil && envelope.EventID != "" && len(envelope.Payload) > 0 {
var result imkafka.CommandResult
if err = json.Unmarshal(envelope.Payload, &result); err != nil {
return err
}
if result.CommandEventID == "" {
result.CommandEventID = envelope.ParentEventID
}
if result.TenantCode == "" {
result.TenantCode = envelope.TenantCode
}
if result.EventID == "" {
result.EventID = envelope.EventID
}
return imkafka.ApplyCommandResult(ctx, result)
}
var result imkafka.CommandResult
if err = json.Unmarshal(mqMsg.Body, &result); err != nil {
return err
}
return imkafka.ApplyCommandResult(ctx, result)
}