-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
47 lines (39 loc) · 903 Bytes
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package runtime
import "github.com/weihaiyang/go-core/storage"
// NewQueue 创建对应上下文队列
func NewQueue(prefix string, queue storage.AdapterQueue) storage.AdapterQueue {
return &Queue{
prefix: prefix,
queue: queue,
}
}
type Queue struct {
prefix string
queue storage.AdapterQueue
}
func (e *Queue) String() string {
return e.queue.String()
}
// Register 注册消费者
func (e *Queue) Register(name string, f storage.ConsumerFunc) {
e.queue.Register(name, f)
}
// Append 增加数据到生产者
func (e *Queue) Append(message storage.Messager) error {
values := message.GetValues()
if values == nil {
values = make(map[string]interface{})
}
values[storage.PrefixKey] = e.prefix
return e.queue.Append(message)
}
// Run 运行
func (e *Queue) Run() {
e.queue.Run()
}
// Shutdown 停止
func (e *Queue) Shutdown() {
if e.queue != nil {
e.queue.Shutdown()
}
}