summaryrefslogtreecommitdiff
path: root/pkg/interface/pubsub/interface.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-18 01:06:16 +0300
committerValery Piashchynski <[email protected]>2021-06-18 01:06:16 +0300
commitfe7bb0fe758d573fe353df028257ed66c6eccf66 (patch)
tree74392f8e61e96c85f0d8b684cfc08e3fc3664ae9 /pkg/interface/pubsub/interface.go
parent68ff941c4226074206ceed9c30bd95317aa0e9fc (diff)
- Rework main parts
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg/interface/pubsub/interface.go')
-rw-r--r--pkg/interface/pubsub/interface.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/pkg/interface/pubsub/interface.go b/pkg/interface/pubsub/interface.go
new file mode 100644
index 00000000..30b544db
--- /dev/null
+++ b/pkg/interface/pubsub/interface.go
@@ -0,0 +1,55 @@
+package pubsub
+
+import websocketsv1 "github.com/spiral/roadrunner/v2/pkg/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() (*websocketsv1.Message, error)
+}
+
+type PSProvider interface {
+ PSProvide(key string) (PubSub, error)
+}