Streaming

Configuration

Config structs, YAML examples, and option helpers for Streaming

YAML Configuration Example

config.yaml
extensions:
  streaming:
    backend: "local"                 # "local", "redis", "nats"
    backendURLs: []
    backendUsername: ""
    backendPassword: ""

    # Feature toggles
    enableRooms: true
    enableChannels: true
    enablePresence: true
    enableTypingIndicators: true
    enableMessageHistory: true
    enableDistributed: false

    # Connection limits
    maxConnectionsPerUser: 5
    maxRoomsPerUser: 50
    maxChannelsPerUser: 100

    # Message limits
    maxMessageSize: 65536            # 64 KB
    maxMessagesPerSecond: 100

    # Timeouts
    pingInterval: "30s"
    pongTimeout: "10s"
    writeTimeout: "10s"

    # Buffer sizes
    readBufferSize: 4096
    writeBufferSize: 4096

    # Message history
    messageRetention: "720h"         # 30 days
    messageCleanup: "1h"
    maxMessagesPerRoom: 100000

    # Presence
    presenceTimeout: "5m"
    presenceCleanup: "1m"

    # Typing
    typingTimeout: "3s"
    typingCleanup: "1s"
    maxTypingUsersPerRoom: 10

    # Distributed
    nodeID: ""                       # auto-generated if empty
    heartbeatInterval: "10s"
    nodeTimeout: "30s"

    # TLS (for Redis/NATS backends)
    tlsEnabled: false
    tlsCertFile: ""
    tlsKeyFile: ""
    tlsCAFile: ""

The extension loads config from extensions.streaming first, falling back to streaming.

Programmatic Configuration

ext := streaming.NewExtension(
    streaming.WithRedisBackend("redis://localhost:6379"),
    streaming.WithFeatures(true, true, true, true, true),
    streaming.WithConnectionLimits(10, 100, 200),
    streaming.WithMessageLimits(32768, 50),
    streaming.WithPresenceTimeout(10 * time.Minute),
)

Config Struct Reference

Config

FieldTypeDefaultDescription
Backendstring"local"Backend: "local", "redis", "nats"
BackendURLs[]string[]Backend connection URLs
EnableRoomsbooltrueEnable room support
EnableChannelsbooltrueEnable channel pub/sub
EnablePresencebooltrueEnable presence tracking
EnableTypingIndicatorsbooltrueEnable typing indicators
EnableMessageHistorybooltrueEnable message persistence
EnableDistributedboolfalseEnable distributed mode
MaxConnectionsPerUserint5Max concurrent connections per user
MaxRoomsPerUserint50Max rooms a user can join
MaxChannelsPerUserint100Max channel subscriptions
MaxMessageSizeint65536Max message size in bytes
MaxMessagesPerSecondint100Per-user rate limit
PingIntervaltime.Duration30sWebSocket ping interval
PongTimeouttime.Duration10sPong response timeout
WriteTimeouttime.Duration10sWrite deadline
MessageRetentiontime.Duration720h (30 days)Message history retention
PresenceTimeouttime.Duration5mPresence expiration
TypingTimeouttime.Duration3sTyping indicator expiration
MaxTypingUsersPerRoomint10Max concurrent typing users
NodeIDstring""Node ID (auto-generated if empty)

Option Helpers

FunctionDescription
WithBackend(backend)Set the backend type
WithBackendURLs(urls...)Set backend connection URLs
WithRedisBackend(url)Configure Redis backend
WithNATSBackend(urls...)Configure NATS backend
WithLocalBackend()Use local in-memory backend
WithFeatures(rooms, channels, presence, typing, history)Toggle feature flags
WithConnectionLimits(perUser, roomsPerUser, channelsPerUser)Set connection limits
WithMessageLimits(maxSize, maxPerSecond)Set message constraints
WithTimeouts(ping, pong, write)Set timeout durations
WithBufferSizes(read, write)Set buffer sizes
WithMessageRetention(retention)Set history retention period
WithPresenceTimeout(timeout)Set presence expiration
WithTypingTimeout(timeout)Set typing indicator timeout
WithNodeID(nodeID)Set node identifier
WithTLS(certFile, keyFile, caFile)Enable TLS for backends
WithAuthentication(username, password)Set backend credentials
WithConfig(config)Provide a complete config struct

How is this guide?

On this page