-
Notifications
You must be signed in to change notification settings - Fork 9
/
pubsub.go
22 lines (19 loc) · 742 Bytes
/
pubsub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package cache
import "context"
// Pubsub is the interface to deal with the message queue
type Pubsub interface {
// Pub publishes the message to the message queue with specified topic
Pub(context context.Context, topic string, message []byte) error
// Sub subscribes messages from the message queue with specified topics
Sub(context context.Context, topic ...string) <-chan Message
// Close closes the subscription only if Sub() is used.
// In other word, should handle un-normal usage when Sub() didn't happen before.
Close()
}
// Message is the interface to receive messages from message queue
type Message interface {
// Topic returns the topic
Topic() string
// Content returns the content of the message
Content() []byte
}