summaryrefslogtreecommitdiff
path: root/pkg/pubsub/interface.go
blob: 53f92cb8f29f4b1fbc401db7bebe97b22872c895 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package pubsub

import websocketsv1beta "github.com/spiral/roadrunner/v2/proto/websockets/v1beta"

/*
This interface is in BETA. It might be changed.
*/

// PubSub interface designed to implement on any storage type to provide pub-sub abilities
// Publisher used to receive messages from the PHP app via RPC
// Subscriber should be implemented to subscribe to a topics and provide a connections list per topic
// Reader return next message from the channel
type PubSub interface {
	Publisher
	Subscriber
	Reader
}

type SubReader interface {
	Subscriber
	Reader
}

// Subscriber defines the ability to operate as message passing broker.
// BETA interface
type Subscriber interface {
	// Subscribe broker to one or multiple topics.
	Subscribe(connectionID string, topics ...string) error

	// Unsubscribe from one or multiply topics
	Unsubscribe(connectionID string, topics ...string) error

	// Connections returns all connections associated with the particular topic
	Connections(topic string, ret map[string]struct{})
}

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

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

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

type Constructor interface {
	PSConstruct(key string) (PubSub, error)
}