51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
|
// Package event ...
|
||
|
//
|
||
|
// Description : event ...
|
||
|
//
|
||
|
// Author : go_developer@163.com<白茶清欢>
|
||
|
//
|
||
|
// Date : 2024-07-17 14:17
|
||
|
package event
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"git.zhangdeman.cn/zhangdeman/event/define"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestInitMemoryEvent(t *testing.T) {
|
||
|
InitMemoryEvent(&define.MemoryEventConfig{
|
||
|
MessageBufferSize: 1024,
|
||
|
CloseMaxWaitTime: 5000,
|
||
|
})
|
||
|
go func() {
|
||
|
for {
|
||
|
time.Sleep(time.Second)
|
||
|
MemoryEventClient.SendEventAsync(context.Background(), &define.EventData{
|
||
|
EventType: "TEST",
|
||
|
TraceID: time.Now().Format("2006-01-02 15:04:05"),
|
||
|
Host: "",
|
||
|
Timestamp: time.Now().Unix(),
|
||
|
SystemTimestamp: 0,
|
||
|
Key: "",
|
||
|
Data: nil,
|
||
|
}, func(ctx context.Context, eventResult *define.SendResult) {
|
||
|
fmt.Println("消息发送成功")
|
||
|
}, func(ctx context.Context, eventData *define.EventData, eventResult *define.SendResult, err error) {
|
||
|
fmt.Println("消息发送失败")
|
||
|
})
|
||
|
}
|
||
|
}()
|
||
|
MemoryEventClient.ConsumeEvent(func(eventData *define.EventData) (map[string]any, error) {
|
||
|
byteData, _ := json.Marshal(eventData)
|
||
|
fmt.Println(string(byteData))
|
||
|
return map[string]any{}, nil
|
||
|
}, nil, nil)
|
||
|
for {
|
||
|
|
||
|
}
|
||
|
}
|