github.com/anycable/anycable-go@v1.5.1/broadcast/broadcast.go (about)

     1  // This package contains different message broadcast handler implemenentations.
     2  // Broadcast handler is responsible for consumeing broadcast messages from the outer world and
     3  // routing them to the application node.
     4  //
     5  // NOTE: There could be multiple broadcast handlers running at the same time.
     6  package broadcast
     7  
     8  import (
     9  	"context"
    10  )
    11  
    12  //go:generate mockery --name Broadcaster --output "../mocks" --outpkg mocks
    13  type Broadcaster interface {
    14  	Start(done chan (error)) error
    15  	Shutdown(ctx context.Context) error
    16  	// Returns true if the broadcaster fan-outs the same event
    17  	// to all nodes. Such subscriber shouldn't be used with real pub/sub
    18  	// engines (which are responsible for message distribution)
    19  	IsFanout() bool
    20  }
    21  
    22  //go:generate mockery --name Handler --output "../mocks" --outpkg mocks
    23  type Handler interface {
    24  	// Handle broadcast message delivered only to this node (and pass it through the broker)
    25  	// (Used by single-node broadcasters)
    26  	HandleBroadcast(json []byte)
    27  	// Handle broadcast message delivered to all nodes
    28  	// (Used by fan-out broadcasters)
    29  	HandlePubSub(json []byte)
    30  }