-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
63 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
63
package nsqd
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
}