Files

51 lines
1.5 KiB
Go

// package httpqueues
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <xxx@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package httpqueues
import (
"context"
"encoding/json"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/cmd/inithttp"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/queue"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func init() {
inithttp.RegisterHttpInitFunc("init "+consts.BroadcastDbChg, func(ctx context.Context) error {
queue.NewConsumer(gctx.New(), BroadcastDbChgQueue, &queue.Config{
Workers: 10,
})
queue.NewProducer(gctx.New(), queue.QueueTypeMemory, consts.BroadcastDbChg, &queue.Config{})
return nil
})
}
type qBroadcastDbChg struct{}
var BroadcastDbChgQueue = &qBroadcastDbChg{}
func (q *qBroadcastDbChg) GetTopic() string {
return consts.BroadcastDbChg
}
func (q *qBroadcastDbChg) GetType() queue.QueueType {
return queue.QueueTypeMemory
}
func (q *qBroadcastDbChg) Handle(ctx context.Context, p queue.Payload) error {
var data model.BroadcastDbChgCache
if err := json.Unmarshal(p.Data, &data); err != nil {
g.Log().Error(ctx, "qBroadcastDbChg.Handle json.Unmarshal err.", err)
return err
}
return service.MemoryDB().EventHandler(ctx, &data)
}