diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/pubsub/interface.go | 9 | ||||
-rw-r--r-- | pkg/pubsub/psmessage.go | 15 |
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) +} |