diff options
author | Valery Piashchynski <[email protected]> | 2021-06-21 11:41:42 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-21 11:41:42 +0300 |
commit | bdcfdd28d705e401973da2beb8a11543e362bda4 (patch) | |
tree | 6a80b5b78ce18c7ddf298861d5b0cd05d8c64ccf /pkg/pubsub | |
parent | cee4bc46097506d6e892b6af194751434700621a (diff) | |
parent | 87d023d32feef5fe28c9bb65a796deb77d536b15 (diff) |
Merge remote-tracking branch 'origin/master' into feature/jobs_plugin
# Conflicts:
# plugins/websockets/plugin.go
Diffstat (limited to 'pkg/pubsub')
-rw-r--r-- | pkg/pubsub/interface.go | 18 | ||||
-rw-r--r-- | pkg/pubsub/psmessage.go | 15 |
2 files changed, 26 insertions, 7 deletions
diff --git a/pkg/pubsub/interface.go b/pkg/pubsub/interface.go index d021dbbe..06252d70 100644 --- a/pkg/pubsub/interface.go +++ b/pkg/pubsub/interface.go @@ -1,7 +1,5 @@ package pubsub -import websocketsv1 "github.com/spiral/roadrunner/v2/pkg/proto/websockets/v1beta" - /* This interface is in BETA. It might be changed. */ @@ -16,6 +14,11 @@ type PubSub interface { Reader } +type SubReader interface { + Subscriber + Reader +} + // Subscriber defines the ability to operate as message passing broker. // BETA interface type Subscriber interface { @@ -33,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() (*websocketsv1.Message, error) + Next() (*Message, error) } -type PSProvider interface { - PSProvide(key string) (PubSub, 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) +} |