-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmq.go
57 lines (46 loc) · 1.68 KB
/
mq.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
package mq
// Message is the primary citizen of mq. It is the m in the mq.
type Message struct {
// Type is usually an identifier for the type of message/topic.
Type string
// Headers are like the http/tcp headers and can carry information
// about the message itself.
Header Header
// Body is the actual body of the message.
Body []byte
// Ack while self explanatory can also be a destructor(like sqs delete).
Ack func() error
// Requeue is a specification/function that lets the caller put
// the message back in the queue.
// mq implementations that support a return to queue can go
// ahead and use this feature.
Requeue func() error
// Deadletter is a specification/function that lets the caller put
// the message in a deadletter queue.
Deadletter func() error
// Error holds the underlying error in case consume encountered an error.
Error error
}
// Header represents the key-value pairs in an mq header.
type Header map[string]interface{}
// Subscriber is a representation of a consumer of queues. Its job
// is to return messages (order depends on the type of mq implemented).
type Subscriber interface {
Subscribe() (<-chan Message, error)
Close() error
}
// Publisher is a representation of a pusher of queues. Its job
// is to be able to push messages to the mq itself.
type Publisher interface {
Publish(messageType string, message Message) error
Close() error
}
// Logger is a very basic pluggable module some rmq implementations
// optionally accept to log certain important events. Note that this
// should always be an optional feature.
type Logger interface {
Info(args ...interface{})
Debug(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
}