github.com/anycable/anycable-go@v1.5.1/pubsub/subscriber.go (about) 1 package pubsub 2 3 import ( 4 "context" 5 6 "github.com/anycable/anycable-go/common" 7 ) 8 9 // Subscriber is responsible for subscribing to individual streams and 10 // and publishing messages to streams 11 // 12 //go:generate mockery --name Subscriber --output "../mocks" --outpkg mocks 13 type Subscriber interface { 14 Start(done chan (error)) error 15 Shutdown(ctx context.Context) error 16 Broadcast(msg *common.StreamMessage) 17 BroadcastCommand(msg *common.RemoteCommandMessage) 18 Subscribe(stream string) 19 Unsubscribe(stream string) 20 IsMultiNode() bool 21 } 22 23 type Handler interface { 24 Broadcast(msg *common.StreamMessage) 25 ExecuteRemoteCommand(msg *common.RemoteCommandMessage) 26 } 27 28 type LegacySubscriber struct { 29 node Handler 30 } 31 32 var _ Subscriber = (*LegacySubscriber)(nil) 33 34 // NewLegacySubscriber creates a legacy subscriber implementation to work with legacy Redis and NATS broadcasters 35 func NewLegacySubscriber(node Handler) *LegacySubscriber { 36 return &LegacySubscriber{node: node} 37 } 38 39 func (LegacySubscriber) Start(done chan (error)) error { 40 return nil 41 } 42 43 func (LegacySubscriber) Shutdown(ctx context.Context) error { 44 return nil 45 } 46 47 func (LegacySubscriber) Subscribe(stream string) { 48 } 49 50 func (LegacySubscriber) Unsubscribe(stream string) { 51 } 52 53 func (s *LegacySubscriber) Broadcast(msg *common.StreamMessage) { 54 s.node.Broadcast(msg) 55 } 56 57 func (s *LegacySubscriber) BroadcastCommand(cmd *common.RemoteCommandMessage) { 58 s.node.ExecuteRemoteCommand(cmd) 59 } 60 61 func (s *LegacySubscriber) IsMultiNode() bool { 62 return false 63 }