50 lines
1.3 KiB
Go
50 lines
1.3 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 result imkafka.CommandResult
|
|
if err = json.Unmarshal(mqMsg.Body, &result); err != nil {
|
|
return err
|
|
}
|
|
if result.CommandID == "" && result.CommandEventID == "" {
|
|
var envelope imkafka.Envelope
|
|
if err = json.Unmarshal(mqMsg.Body, &envelope); err != nil {
|
|
return err
|
|
}
|
|
if len(envelope.Payload) > 0 {
|
|
if err = json.Unmarshal(envelope.Payload, &result); err != nil {
|
|
return err
|
|
}
|
|
result.EventID = envelope.EventID
|
|
result.TraceID = envelope.TraceID
|
|
result.TenantCode = envelope.TenantCode
|
|
result.OccurredAt = envelope.OccurredAt
|
|
}
|
|
}
|
|
return imkafka.ApplyCommandResult(ctx, result)
|
|
}
|