summaryrefslogtreecommitdiff
path: root/pkg/pubsub/interface.go
blob: 80dab0c32e4c254d45a5de30e5f0890670fba632 (plain)
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
package pubsub

// PubSub ...
type PubSub interface {
	Publisher
	Subscriber
	Reader
}

// Subscriber defines the ability to operate as message passing broker.
type Subscriber interface {
	// Subscribe broker to one or multiple topics.
	Subscribe(topics ...string) error
	// Unsubscribe from one or multiply topics
	Unsubscribe(topics ...string) error
}

// Publisher publish one or more messages
type Publisher interface {
	// Publish one or multiple Channel.
	Publish(messages []Message) error

	// PublishAsync publish message and return immediately
	// If error occurred it will be printed into the logger
	PublishAsync(messages []Message)
}

// Reader interface should return next message
type Reader interface {
	Next() (Message, error)
}

type Message interface {
	Command() string
	Payload() []byte
	Topics() []string
	Broker() string
}