hotgo/server/internal/library/queue/producer.go

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package queue
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queue
import (
"github.com/gogf/gf/v2/util/gconv"
)
// Push 推送队列
func Push(topic string, data interface{}) (err error) {
q, err := InstanceProducer()
if err != nil {
return
}
mqMsg, err := q.SendMsg(topic, gconv.String(data))
ProducerLog(ctx, topic, mqMsg, err)
return
}
// DelayPush 推送延迟队列
// redis delay 传入 秒。如10代表延迟10秒
// rocketmq delay 传入 延迟级别。如2代表延迟5秒
// rocketmq reference delay level definition: 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
// rocketmq delay level starts from 1. for example, if we set param level=1, then the delay time is 1s.
func DelayPush(topic string, data interface{}, delay int64) (err error) {
q, err := InstanceProducer()
if err != nil {
return
}
mqMsg, err := q.SendDelayMsg(topic, gconv.String(data), delay)
ProducerLog(ctx, topic, mqMsg, err)
return
}