mq - GStones/moke-kit GitHub Wiki
本文档介绍了moke-kit提供的message queue组件的使用方法。
- 注入NatsModule 到你的
Main
中。 - 设置环境变量NATS_URL
来指定Nats的连接地址,默认值为
nats://localhost:4222
。 - 使用
common.NatsHeader.CreateTopic(topic)
来创建主题,并使用d.mq.Publish
来发布消息。//tips: must use common.NatsHeader to create topic natsTopic := common.NatsHeader.CreateTopic(topic) if err := d.mq.Publish(natsTopic,miface.WithBytes([]byte(message))); err != nil { return err }
- 注入LocalModule 到你的
Main
中。 - 使用
common.LocalHeader.CreateTopic(topic)
来创建主题,并使用d.mq.Publish
来发布消息。//tips: must use common.LocalHeader to create topic localTopic := common.LocalHeader.CreateTopic(topic) if err := d.mq.Publish(alTopic,ace.WithBytes([]byte(message));err != nil { return err }
- if you need other mq, you can create an issue, I will add it in the future.