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
     }

local

  • 注入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
    }

others

  • if you need other mq, you can create an issue, I will add it in the future.
⚠️ **GitHub.com Fallback** ⚠️