From 5667d34e59135301db9580f9d4522080481d0618 Mon Sep 17 00:00:00 2001 From: lab Date: Tue, 28 Dec 2021 01:42:42 +0800 Subject: [PATCH] feat: add pubsub --- internal/pkg/pubsub/pubsub.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/pkg/pubsub/pubsub.go diff --git a/internal/pkg/pubsub/pubsub.go b/internal/pkg/pubsub/pubsub.go new file mode 100644 index 0000000..7a916d0 --- /dev/null +++ b/internal/pkg/pubsub/pubsub.go @@ -0,0 +1,27 @@ +package pubsub + +import "context" + +type Subject string + +func (subject Subject) String() string { + return string(subject) +} + +type Message interface{} + +type Publishing struct{} + +type PublishOption func(*Publishing) + +type Publisher interface { + Publish(context.Context, Subject, Message, ...PublishOption) error +} + +type MessageHandler interface { + HandleMessage(context.Context, *Message) error +} + +type Subscriber interface { + Subscribe(context.Context, Subject, MessageHandler) error +}