summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-20 16:40:14 +0300
committerValery Piashchynski <[email protected]>2021-06-20 16:40:14 +0300
commit2dd30155de6faaf6005027d5337a840310c827f9 (patch)
treeaa6f0ce2d2db2047b7e729b16dd70d721f4bae55 /pkg
parent25dfc0d837827d0d1c729d323dd651ca6163fe09 (diff)
- Update redis/memory pubsubs
- Rework internal message bus - Add new tests for the broadcast plugin and include them into the GA Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/pubsub/interface.go9
-rw-r--r--pkg/pubsub/psmessage.go15
2 files changed, 19 insertions, 5 deletions
diff --git a/pkg/pubsub/interface.go b/pkg/pubsub/interface.go
index 53f92cb8..06252d70 100644
--- a/pkg/pubsub/interface.go
+++ b/pkg/pubsub/interface.go
@@ -1,7 +1,5 @@
package pubsub
-import websocketsv1beta "github.com/spiral/roadrunner/v2/proto/websockets/v1beta"
-
/*
This interface is in BETA. It might be changed.
*/
@@ -38,18 +36,19 @@ type Subscriber interface {
// BETA interface
type Publisher interface {
// Publish one or multiple Channel.
- Publish(messages []byte) error
+ Publish(message *Message) error
// PublishAsync publish message and return immediately
// If error occurred it will be printed into the logger
- PublishAsync(messages []byte)
+ PublishAsync(message *Message)
}
// Reader interface should return next message
type Reader interface {
- Next() (*websocketsv1beta.Message, error)
+ Next() (*Message, error)
}
+// Constructor is a special pub-sub interface made to return a constructed PubSub type
type Constructor interface {
PSConstruct(key string) (PubSub, error)
}
diff --git a/pkg/pubsub/psmessage.go b/pkg/pubsub/psmessage.go
new file mode 100644
index 00000000..e33d9284
--- /dev/null
+++ b/pkg/pubsub/psmessage.go
@@ -0,0 +1,15 @@
+package pubsub
+
+import json "github.com/json-iterator/go"
+
+// Message represents a single message with payload bound to a particular topic
+type Message struct {
+ // Topic (channel in terms of redis)
+ Topic string `json:"topic"`
+ // Payload (on some decode stages might be represented as base64 string)
+ Payload []byte `json:"payload"`
+}
+
+func (m *Message) MarshalBinary() (data []byte, err error) {
+ return json.Marshal(m)
+}