wsserver

package
v1.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigAckTimeout      = "ackTimeout"
	ConfigReadBufferSize  = "readBufferSize"
	ConfigWriteBufferSize = "writeBufferSize"
)

Variables

This section is empty.

Functions

func InitConfig added in v1.4.6

func InitConfig(conf config.Section)

Types

type BatchHeader added in v1.4.6

type BatchHeader struct {
	BatchNumber int64  `json:"batchNumber"`
	Stream      string `json:"stream"`
}

type Protocol added in v1.4.6

type Protocol interface {
	// Broadcast performs best-effort delivery to all connections currently active on the specified stream
	Broadcast(ctx context.Context, stream string, payload interface{})

	// NextRoundTrip blocks until at least one connection is started on the stream, and then
	// returns an interface that can be used to send a payload to exactly one of the attached
	// connections, and receive an ack/error from just the one connection that was picked.
	// - Returns an error if the context is closed.
	RoundTrip(ctx context.Context, stream string, payload WSBatch) (*WebSocketCommandMessage, error)
}

The Protocol interface layers a protocol on top of raw websockets, that allows the server side to:

  • Model the concept of multiple "streams" on a single WebSocket
  • Block until 1 or more connections are available that have "started" a particular stream
  • Send a broadcast to all connections on a stream
  • Send a single payload to a single selected connection on a stream, and wait for an "ack" back from that specific websocket connection (or that websocket connection to disconnect)

NOTE: This replaces a previous WebSocketChannels interface, which started its life in 2018

and attempted to solve the above problem set in a different way that had a challenging timing issue.

type WSBatch added in v1.4.6

type WSBatch interface {
	GetBatchHeader() *BatchHeader
}

WSBatch is any serializable structure that contains the batch header

type WebSocketCommandMessage

type WebSocketCommandMessage struct {
	Type        string `json:"type,omitempty"`
	Stream      string `json:"stream,omitempty"` // name of the event stream
	Message     string `json:"message,omitempty"`
	BatchNumber int64  `json:"batchNumber,omitempty"`
}

type WebSocketServer

type WebSocketServer interface {
	Protocol
	Handler(w http.ResponseWriter, r *http.Request)
	Close()
}

WebSocketServer is the full server interface with the init call

func NewWebSocketServer

func NewWebSocketServer(bgCtx context.Context, config *WebSocketServerConfig) WebSocketServer

NewWebSocketServer create a new server with a simplified interface

type WebSocketServerConfig added in v1.4.6

type WebSocketServerConfig struct {
	AckTimeout      time.Duration
	ReadBufferSize  int64
	WriteBufferSize int64
}

func GenerateConfig added in v1.4.6

func GenerateConfig(conf config.Section) *WebSocketServerConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL