提交 92bdace8 authored 作者: gukai's avatar gukai

增加通知服务README

上级 16f0a1c0
......@@ -8,29 +8,8 @@
## 限制
golang版本 >= 1.14
golang版本 >= 1.16
## 使用方法
```golang
package main
import (
"github.com/gogf/gf/net/ghttp"
logs "gitlab.jxhh.com/stbz/library.git/logs"
)
//记录普通日志
logs.Info("存储路径", "格式""格式信息")
requestId := logs.CreateRequestId() //初始化请求id
responseTime := time.Now().UnixNano()/1e6 - r.EnterTime //响应时间 毫秒级
//组装请求日志参数
requestLogreq := logs.RequestLogReq{
"request",r.RequestURI,requestId,r.Method, string(r.GetBody()), r.Response.BufferString(),r.GetError(), r.GetHeader("service_name"),responseTime,
}
logs.RequestLog(requestLogreq) //记录请求日志
```
## stbz/library
胜天半子内部调用库
## 地址
https://gitlab.jxhh.com/stbz/library
## 限制
golang版本 >= 1.16
## 使用方法
```golang
package main
import (
"github.com/gogf/gf/net/ghttp"
logs "gitlab.jxhh.com/stbz/library.git/logs"
)
//记录普通日志
logs.Info("存储路径", "格式""格式信息")
requestId := logs.CreateRequestId() //初始化请求id
responseTime := time.Now().UnixNano()/1e6 - r.EnterTime //响应时间 毫秒级
//组装请求日志参数
requestLogreq := logs.RequestLogReq{
"request",r.RequestURI,requestId,r.Method, string(r.GetBody()), r.Response.BufferString(),r.GetError(), r.GetHeader("service_name"),responseTime,
}
logs.RequestLog(requestLogreq) //记录请求日志
```
## stbz/library
胜天半子内部调用库
## 地址
https://gitlab.jxhh.com/stbz/library
## 限制
golang版本 >= 1.16
## 使用方法
### 生产者 在boot/boot.go
```golang
package boot
import (
"github.com/gogf/gf/frame/g"
"gitlab.jxhh.com/stbz/library.git/notify"
)
func init() {
//加载nsq配置文件
addr := g.Cfg().GetString("messagequeue.link")
notify.New(&notify.NsqConfig{Addr: addr})
}
```
### 生产者 服务中调用
```golang
package test
import (
"github.com/gogf/gf/frame/g"
"gitlab.jxhh.com/stbz/library.git/notify"
)
func Servie() {
//推送内容
msgData := &define.CommonMessage{Source: upstream.Cloud, MsgSendTime: gtime.Timestamp()}
msgJsonData,err := json.Marshal(msgData)
if logs.CheckErr(err, "Marshal"){
return
}
//调用方法
err = notify.NsqProducers.Publish(pushTopic,string(msgJsonData))
}
```
### 消费者 在脚本文件 script/script.go消费
```golang
package script
import (
"github.com/gogf/gf/net/ghttp"
logs "gitlab.jxhh.com/stbz/library.git/notify"
)
func Run() {
//加载nsq配置文件
addr := g.Cfg().GetString("messagequeue.link")
// 初始化要消费的topic channel和消费的结构体
notify.InitConsumer(&notify.NsqConfig{Addr: addr, Channel: notify.MsgCloudTopic, Topic: notify.MsgCloudTopic, Handler: &message.CloudMessage})
// 多个消费调用的示例
notify.InitConsumer(&notify.NsqConfig{Addr: addr, Channel: notify.NotifyTopic, Topic: notify.NotifyTopic, Handler: &handle.Message})
select {}
}
```
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论