forked from nsqio/nsq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
62 lines (51 loc) · 1.08 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bytes"
"github.com/bitly/go-nsq"
)
// BackendQueue represents the behavior for the secondary message
// storage system
type BackendQueue interface {
Put([]byte) error
ReadChan() chan []byte // this is expected to be an *unbuffered* channel
Close() error
Delete() error
Depth() int64
Empty() error
}
type DummyBackendQueue struct {
readChan chan []byte
}
func NewDummyBackendQueue() BackendQueue {
return &DummyBackendQueue{readChan: make(chan []byte)}
}
func (d *DummyBackendQueue) Put([]byte) error {
return nil
}
func (d *DummyBackendQueue) ReadChan() chan []byte {
return d.readChan
}
func (d *DummyBackendQueue) Close() error {
return nil
}
func (d *DummyBackendQueue) Delete() error {
return nil
}
func (d *DummyBackendQueue) Depth() int64 {
return int64(0)
}
func (d *DummyBackendQueue) Empty() error {
return nil
}
func WriteMessageToBackend(buf *bytes.Buffer, msg *nsq.Message, bq BackendQueue) error {
buf.Reset()
err := msg.Write(buf)
if err != nil {
return err
}
err = bq.Put(buf.Bytes())
if err != nil {
return err
}
return nil
}