summaryrefslogtreecommitdiff
path: root/plugins/broadcast/interface.go
blob: 47c779b51936b0aa716dd5ec7f09b33a1388de43 (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
39
40
41
package broadcast

import (
	"encoding/json"
)

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

// Storage used to store patterns and topics
type Storage interface {
	// Store connection uuid associated with the provided topics
	Store(uuid string, topics ...string)
	// StorePattern stores pattern associated with the particular connection
	StorePattern(uuid string, pattern string)

	// GetConnection returns connections for the particular pattern
	GetConnection(pattern string) []string

	// Construct is a constructor for the storage according to the provided configuration key (broadcast.websocket for example)
	Construct(key string) (Storage, error)
}

type Publisher interface {
	// Publish one or multiple Channel.
	Publish(messages ...*Message) error
}

// Message represent single message.
type Message struct {
	// Topic message been pushed into.
	Topic string `json:"topic"`

	// Payload to be broadcasted. Must be valid json when transferred over RPC.
	Payload json.RawMessage `json:"payload"`
}