adapter

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package adapter provides configuration options for the PostgreSQL-based Socket.IO adapter.

Package adapter defines types and interfaces for the PostgreSQL-based Socket.IO adapter implementation. It uses PostgreSQL LISTEN/NOTIFY for inter-node communication in a clustered Socket.IO environment.

Package adapter provides a PostgreSQL-based adapter implementation for Socket.IO clustering. It uses PostgreSQL LISTEN/NOTIFY for pub/sub communication between nodes, with an attachment table for payloads that exceed the 8000-byte NOTIFY limit.

Index

Constants

View Source
const (
	// DefaultChannelPrefix is the default PostgreSQL channel prefix for LISTEN/NOTIFY.
	DefaultChannelPrefix = "socket.io"

	// DefaultTableName is the default name for the attachment storage table.
	DefaultTableName = "socket_io_attachments"

	// DefaultPayloadThreshold is the default byte threshold for using attachment storage.
	// PostgreSQL's NOTIFY payload limit is 8000 bytes.
	DefaultPayloadThreshold = 8000

	// DefaultCleanupInterval is the default interval in milliseconds for cleaning up old attachments.
	DefaultCleanupInterval int64 = 30_000

	// DefaultHeartbeatInterval is the default interval between heartbeats.
	DefaultHeartbeatInterval = 5_000 * time.Millisecond

	// DefaultHeartbeatTimeout is the default timeout for heartbeat responses.
	DefaultHeartbeatTimeout int64 = 10_000
)

Default configuration values for PostgresAdapterOptions.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastAck

type BroadcastAck = adapter.BroadcastAck

BroadcastAck is an alias for adapter.BroadcastAck.

type BroadcastClientCount

type BroadcastClientCount = adapter.BroadcastClientCount

BroadcastClientCount is an alias for adapter.BroadcastClientCount.

type BroadcastMessage

type BroadcastMessage = adapter.BroadcastMessage

BroadcastMessage is an alias for adapter.BroadcastMessage.

type ClusterMessage

type ClusterMessage = adapter.ClusterMessage

ClusterMessage is an alias for adapter.ClusterMessage.

type ClusterResponse

type ClusterResponse = adapter.ClusterResponse

ClusterResponse is an alias for adapter.ClusterResponse.

type DisconnectSocketsMessage

type DisconnectSocketsMessage = adapter.DisconnectSocketsMessage

DisconnectSocketsMessage is an alias for adapter.DisconnectSocketsMessage.

type FetchSocketsMessage

type FetchSocketsMessage = adapter.FetchSocketsMessage

FetchSocketsMessage is an alias for adapter.FetchSocketsMessage.

type FetchSocketsResponse

type FetchSocketsResponse = adapter.FetchSocketsResponse

FetchSocketsResponse is an alias for adapter.FetchSocketsResponse.

type NotificationMessage

type NotificationMessage = postgres.NotificationMessage

NotificationMessage represents a message received via PostgreSQL LISTEN/NOTIFY.

type PostgresAdapter

type PostgresAdapter interface {
	adapter.ClusterAdapterWithHeartbeat

	// SetPostgres configures the PostgreSQL client for the adapter.
	SetPostgres(*postgres.PostgresClient)

	// Cleanup registers a cleanup callback to be called when the adapter is closed.
	Cleanup(func())

	// SetChannel sets the notification channel for this adapter.
	SetChannel(string)

	// OnNotification processes a raw notification payload from PostgreSQL LISTEN/NOTIFY.
	OnNotification(string)
}

PostgresAdapter defines the interface for a PostgreSQL-based Socket.IO adapter. It extends ClusterAdapterWithHeartbeat with PostgreSQL-specific functionality.

func MakePostgresAdapter

func MakePostgresAdapter() PostgresAdapter

MakePostgresAdapter creates a new uninitialized postgresAdapter. Call Construct() to complete initialization before use.

func NewPostgresAdapter

func NewPostgresAdapter(nsp socket.Namespace, client *postgres.PostgresClient, opts any) PostgresAdapter

NewPostgresAdapter creates and initializes a new PostgreSQL adapter. This is the preferred way to create a PostgreSQL adapter instance.

type PostgresAdapterBuilder

type PostgresAdapterBuilder struct {
	// Postgres is the PostgreSQL client used for LISTEN/NOTIFY operations.
	Postgres *postgres.PostgresClient
	// Opts contains configuration options for the adapter.
	Opts PostgresAdapterOptionsInterface
	// contains filtered or unexported fields
}

PostgresAdapterBuilder creates PostgreSQL adapters for Socket.IO namespaces. It manages the shared LISTEN connection and notification loop across all namespace adapters.

func (*PostgresAdapterBuilder) New

New creates a new PostgresAdapter for the given namespace. This method implements the socket.AdapterBuilder interface.

type PostgresAdapterOptions

type PostgresAdapterOptions struct {
	emitter.EmitterOptions
	adapter.ClusterAdapterOptions
	// contains filtered or unexported fields
}

PostgresAdapterOptions holds configuration for the PostgreSQL adapter.

Fields:

  • cleanupInterval: The interval in milliseconds between cleanup of old attachments. Default: 30_000 ms.
  • errorHandler: Custom error handler callback. Default: nil (errors are logged via debug).

func DefaultPostgresAdapterOptions

func DefaultPostgresAdapterOptions() *PostgresAdapterOptions

DefaultPostgresAdapterOptions returns a new PostgresAdapterOptions with default values.

func (*PostgresAdapterOptions) Assign

Assign copies non-nil fields from another PostgresAdapterOptionsInterface. This method is useful for merging user-provided options with defaults.

func (*PostgresAdapterOptions) CleanupInterval

func (s *PostgresAdapterOptions) CleanupInterval() int64

CleanupInterval returns the configured cleanup interval in milliseconds. Returns 0 if not set; callers should use DefaultCleanupInterval as fallback.

func (*PostgresAdapterOptions) ErrorHandler

func (s *PostgresAdapterOptions) ErrorHandler() func(error)

ErrorHandler returns the configured error handler callback, or nil if not set.

func (*PostgresAdapterOptions) GetRawCleanupInterval

func (s *PostgresAdapterOptions) GetRawCleanupInterval() types.Optional[int64]

GetRawCleanupInterval returns the raw Optional value for cleanupInterval.

func (*PostgresAdapterOptions) GetRawErrorHandler

func (s *PostgresAdapterOptions) GetRawErrorHandler() types.Optional[func(error)]

GetRawErrorHandler returns the raw Optional value for errorHandler.

func (*PostgresAdapterOptions) SetCleanupInterval

func (s *PostgresAdapterOptions) SetCleanupInterval(interval int64)

SetCleanupInterval sets the cleanup interval in milliseconds.

func (*PostgresAdapterOptions) SetErrorHandler

func (s *PostgresAdapterOptions) SetErrorHandler(handler func(error))

SetErrorHandler sets the error handler callback.

type PostgresAdapterOptionsInterface

type PostgresAdapterOptionsInterface interface {
	emitter.EmitterOptionsInterface
	adapter.ClusterAdapterOptionsInterface

	SetCleanupInterval(int64)
	GetRawCleanupInterval() types.Optional[int64]
	CleanupInterval() int64

	SetErrorHandler(func(error))
	GetRawErrorHandler() types.Optional[func(error)]
	ErrorHandler() func(error)
}

PostgresAdapterOptionsInterface defines the interface for configuring PostgresAdapterOptions. It extends EmitterOptionsInterface and ClusterAdapterOptionsInterface with adapter-specific settings.

type ServerSideEmitMessage

type ServerSideEmitMessage = adapter.ServerSideEmitMessage

ServerSideEmitMessage is an alias for adapter.ServerSideEmitMessage.

type ServerSideEmitResponse

type ServerSideEmitResponse = adapter.ServerSideEmitResponse

ServerSideEmitResponse is an alias for adapter.ServerSideEmitResponse.

type SocketsJoinLeaveMessage

type SocketsJoinLeaveMessage = adapter.SocketsJoinLeaveMessage

SocketsJoinLeaveMessage is an alias for adapter.SocketsJoinLeaveMessage.

Jump to

Keyboard shortcuts

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