sink

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package sink runs configured sinks. CAN/file/null sinks and MQTT QoS 1 broker acknowledgements confirm each message, HTTP POST and PostgreSQL sinks confirm batches, and serve-mode HTTP/TCP sinks broadcast to connected clients, with replay served straight from connector queues (SSE/WS only).

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("sink skipped message")

Functions

func PostgresDDL added in v1.2.5

func PostgresDDL(table string, timescaleDB bool) string

PostgresDDL returns the exact copy/paste schema shown to operators and run by auto-create mode. TimescaleDB must already be installed in the target database; when enabled, the final statement idempotently converts the table into a hypertable using observed_at as its time dimension.

func RetryAfter added in v1.2.4

func RetryAfter(err error) (time.Duration, bool)

RetryAfter returns a server-requested minimum retry delay carried by err. Sinks use this seam to communicate protocol-native backoff without coupling connectors to HTTP response types.

Types

type BatchByteLimiter added in v1.2.6

type BatchByteLimiter interface {
	BatchMaxBytes() int64
}

BatchByteLimiter lets a batch sink bound the transient request/SQL shape in addition to its message-count maximum. The Connector partitions at an Envelope boundary and always sends at least one entry.

type BatchPushReport added in v1.2.6

type BatchPushReport struct {
	Skipped []bool
}

type BatchPusher added in v1.2.4

type BatchPusher interface {
	BatchSize() int
	PushBatch(ctx context.Context, entries []queue.Entry) error
}

BatchPusher confirms an ordered group of queue entries as one sink write. BatchSize is the maximum number of entries the connector should provide; short batches are valid and are delivered without waiting for the batch to fill. A nil error confirms every entry in the supplied batch.

type BroadcastReport

type BroadcastReport struct {
	Accepted       []bool
	RecipientDrops int64
	Err            error
}

type Broadcaster

type Broadcaster interface {
	Broadcast(entries []queue.Entry) BroadcastReport
}

Broadcaster sinks fan out to connected clients without confirmation.

type ConnectorRegistrar

type ConnectorRegistrar interface {
	RegisterConnector(id string, r ReplayReader)
	UnregisterConnector(id string)
}

ConnectorRegistrar lets connectors attach their queue for client replay.

type DataServer

type DataServer struct {
	// contains filtered or unexported fields
}

DataServer hosts serve-mode sink endpoints with dynamically managed routes.

func NewDataServer

func NewDataServer(addr string, log *slog.Logger, options ...DataServerOption) *DataServer

func (*DataServer) Addr

func (d *DataServer) Addr() string

func (*DataServer) RemoveRoute

func (d *DataServer) RemoveRoute(path string)

func (*DataServer) SetRoute

func (d *DataServer) SetRoute(path string, h http.Handler)

func (*DataServer) Start

func (d *DataServer) Start() error

func (*DataServer) State added in v1.2.6

func (d *DataServer) State() (string, error)

State reports whether serve-mode sink routes are currently reachable. A listener failure remains observable while the recovery loop is backing off.

func (*DataServer) Stop

func (d *DataServer) Stop(ctx context.Context) error

Stop cancels all active request contexts (ending SSE/WS streams), then shuts the server down, waiting for handlers up to ctx's deadline.

func (*DataServer) WrapListener added in v1.2.6

func (d *DataServer) WrapListener(ln net.Listener) net.Listener

WrapListener applies the process connection policy supplied by App. TCP sinks use it too, so their accepted clients share the same descriptor budget as admin and HTTP data traffic. A nil DataServer is the standalone/no-policy case used by tests and embeddings.

type DataServerOption added in v1.2.6

type DataServerOption func(*DataServer)

func WithListenerWrapper added in v1.2.6

func WithListenerWrapper(wrapper func(net.Listener) net.Listener) DataServerOption

WithListenerWrapper applies wrapper to every initial or recovered listener. App uses this seam to share one accepted-connection budget with its admin server; standalone tests and embeddings can omit it.

type DeliveryClass

type DeliveryClass string
const (
	DeliveryConfirmed  DeliveryClass = "confirmed"
	DeliveryResumable  DeliveryClass = "resumable"
	DeliveryBestEffort DeliveryClass = "best_effort"
	DeliveryObserved   DeliveryClass = "observe_only"
)

func DeliveryClassOf

func DeliveryClassOf(r Runtime) DeliveryClass

type DeliveryClassifier

type DeliveryClassifier interface {
	DeliveryClass() DeliveryClass
}

DeliveryClassifier makes the route boundary explicit. Implementations that do not provide it are classified from their Pusher/Broadcaster seam by DeliveryClassOf.

type Pusher

type Pusher interface {
	Push(ctx context.Context, e *msg.Envelope) error
}

Pusher sinks confirm each delivery (for example CAN writes or MQTT broker PUBACKs). ErrSkip means "cannot carry this message, count it and move on" (e.g. an envelope without raw bytes).

type ReplayReader

type ReplayReader interface {
	Read(ctx context.Context, after int64, limit int) ([]queue.Entry, error)
}

ReplayReader is what serve-mode sinks use to replay history for a client.

type Runtime

type Runtime interface {
	ID() string
	Stop()
	State() (string, error)
}

func New

func New(ctx context.Context, cfg model.Sink, mgr *bus.Manager, ds *DataServer, log *slog.Logger, met *metrics.Set) (Runtime, error)

type SelectiveBatchPusher added in v1.2.6

type SelectiveBatchPusher interface {
	BatchSize() int
	PushBatchSelective(ctx context.Context, entries []queue.Entry) (BatchPushReport, error)
}

SelectiveBatchPusher amortizes one durable flush across an ordered group while preserving permanent per-envelope skip reporting. A nil error confirms every non-skipped entry and Skipped must have len(entries).

type WirePusher

type WirePusher interface {
	PushWire(ctx context.Context, e *msg.Envelope) error
}

WirePusher preserves the envelope's original N2K source identity and raw payload instead of re-originating it through Beacon's claimed client.

Jump to

Keyboard shortcuts

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