-
Notifications
You must be signed in to change notification settings - Fork 13
/
interfaces.go
80 lines (65 loc) · 1.48 KB
/
interfaces.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package vega
import (
"errors"
"strings"
)
import "time"
type MailboxStats struct {
Size int
InFlight int
}
var EUnknownMessage = errors.New("Unknown message id")
type MessageId string
type Mailbox interface {
Abandon() error
Push(*Message) error
Poll() (*Message, error)
Ack(MessageId) error
Nack(MessageId) error
AddWatcher() <-chan *Message
AddWatcherCancelable(chan struct{}) <-chan *Message
Stats() *MailboxStats
}
func (id MessageId) LocalIndex() string {
colonPos := strings.LastIndex(string(id), ":")
if colonPos == -1 {
return ""
}
return string(id[colonPos+1:])
}
func (id MessageId) AppendLocalIndex(idxStr string) MessageId {
return id + ":" + MessageId(idxStr)
}
type Acker func() error
type Nacker func() error
type Delivery struct {
Message *Message
Ack Acker
Nack Nacker
}
func NewDelivery(m Mailbox, msg *Message) *Delivery {
return &Delivery{
Message: msg,
Ack: func() error { return m.Ack(msg.MessageId) },
Nack: func() error { return m.Nack(msg.MessageId) },
}
}
type Storage interface {
Declare(string) error
Abandon(string) error
Push(string, *Message) error
Poll(string) (*Delivery, error)
LongPoll(string, time.Duration) (*Delivery, error)
LongPollCancelable(string, time.Duration, chan struct{}) (*Delivery, error)
}
type Pusher interface {
Push(string, *Message) error
}
type RouteTable interface {
Set(string, Pusher) error
Remove(string) error
Get(string) (Pusher, bool)
}
type Byter interface {
Bytes() []byte
}