mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 19:53:55 +08:00
发布v2.3.5版本,本次为优化版本。更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -44,7 +44,7 @@ queue:
|
||||
|
||||
### 一个例子
|
||||
|
||||
每个被发送到队列的消息应该被定义为一个文件的结构。
|
||||
每个被发送到队列的消息应该被定义为一个单独的文件结构。
|
||||
|
||||
例如,如果您需要异步记录系统日志,内容大致如下:
|
||||
|
||||
@@ -63,7 +63,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
jobList = append(jobList, SysLog)
|
||||
queue.RegisterConsumer(SysLog)
|
||||
}
|
||||
|
||||
// SysLog 系统日志
|
||||
@@ -71,13 +71,13 @@ var SysLog = &qSysLog{}
|
||||
|
||||
type qSysLog struct{}
|
||||
|
||||
// getTopic 主题
|
||||
func (q *qSysLog) getTopic() string {
|
||||
// GetTopic 主题
|
||||
func (q *qSysLog) GetTopic() string {
|
||||
return consts.QueueLogTopic
|
||||
}
|
||||
|
||||
// handle 处理消息
|
||||
func (q *qSysLog) handle(ctx context.Context, mqMsg queue.MqMsg) (err error) {
|
||||
// Handle 处理消息
|
||||
func (q *qSysLog) Handle(ctx context.Context, mqMsg queue.MqMsg) (err error) {
|
||||
var data entity.SysLog
|
||||
if err = json.Unmarshal(mqMsg.Body, &data); err != nil {
|
||||
return err
|
||||
@@ -85,7 +85,6 @@ func (q *qSysLog) handle(ctx context.Context, mqMsg queue.MqMsg) (err error) {
|
||||
return service.SysLog().RealWrite(ctx, data)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
下面是将消息添加到队列的方式,大概内容如下:
|
||||
@@ -101,7 +100,9 @@ import (
|
||||
)
|
||||
|
||||
func test() {
|
||||
data := &entity.SysLog{}
|
||||
data := &entity.SysLog{
|
||||
//...
|
||||
}
|
||||
if err := queue.Push(consts.QueueLogTopic, data); err != nil {
|
||||
fmt.Printf("queue.Push err:%+v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user