1 Star 0 Fork 0

庞飞/multiapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
producer.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
庞飞 提交于 2023-10-03 10:28 . 合并主框架
package producerconsumer
import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"gitee.com/pangxianfei/multiapp/kernel/pb"
"gitee.com/pangxianfei/multiapp/kernel/zone"
message "gitee.com/pangxianfei/multiapp/queue/protocol_buffers"
)
type producer struct {
topicName string
channelName string
param proto.Message
retries uint32
delay zone.Duration
}
func NewProducer(topicName string, channelName string, param proto.Message, retries uint32, delay zone.Duration) *producer {
return &producer{
topicName: topicName,
channelName: channelName,
param: param,
retries: retries,
delay: delay,
}
}
func (p *producer) Push() error {
// compress param
paramPb, err := proto.Marshal(p.param)
if err != nil {
return err
}
// compress message
return push(p.topicName, p.channelName, &message.Message{
Hash: "", // is empty when first push
Param: paramPb,
Retries: p.retries,
PushedAt: ptypes.TimestampNow(),
Delay: ptypes.DurationProto(p.delay),
Tried: 0,
})
}
func push(topicName string, channelName string, msg *message.Message) error {
messagePb, err := proto.Marshal(msg)
if err != nil {
return err
}
return Queue().Push(topicName, channelName, *pb.DurationConvert(msg.Delay), messagePb)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/pangxianfei/multiapp.git
git@gitee.com:pangxianfei/multiapp.git
pangxianfei
multiapp
multiapp
v1.1.5

搜索帮助

0d507c66 1850385 C8b1a773 1850385