Documentation
¶
Index ¶
- type Broker
- func (b *Broker) Addr() net.Addr
- func (b *Broker) AuthzEngine() *authz.Engine
- func (b *Broker) Close() error
- func (b *Broker) Handle(cmd protocol.Command, h Handler)
- func (b *Broker) HandleStream(jig context.Context, conn *quic.Conn, stream *quic.Stream, clientIDStr string)
- func (b *Broker) Listen(ctx context.Context, addr string, tlsConf *tls.Config) error
- func (b *Broker) ReplayAAL(ctx context.Context, path string, key []byte) (int, error)
- func (b *Broker) Router() *broker.Router
- func (b *Broker) SetAuthzEngine(e *authz.Engine)
- func (b *Broker) Shutdown(ctx context.Context) error
- type Handler
- type Option
- func WithAAL(l *aal.Log) Option
- func WithAALReplay(path string, key []byte) Option
- func WithAuthz(e *authz.Engine) Option
- func WithCompression(engine broker.CompressionEngine, minBatchSize int) Option
- func WithLogger(l *slog.Logger) Option
- func WithMaxBufSize(n int) Option
- func WithMaxDecompressedPerStream(n int) Option
- func WithReadBufSize(n int) Option
- func WithRouter(r *broker.Router) Option
- func WithTracer(t *tracing.Tracer) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker is a QUIC-based message broker that accepts connections and multiplexes streams. Each stream is handled by a dedicated goroutine that reads binary frames, parses them via protocol.ParseFrame, and dispatches to the registered command handler or the built-in router.
func (*Broker) AuthzEngine ¶ added in v1.12.0
AuthzEngine returns the active authorization engine.
func (*Broker) Handle ¶
Handle registers a handler for the given command. Must be called before Listen.
func (*Broker) HandleStream ¶ added in v1.16.0
func (b *Broker) HandleStream(jig context.Context, conn *quic.Conn, stream *quic.Stream, clientIDStr string)
HandleStream is the public, transport-agnostic entry point for feeding a single bidirectional QUIC stream through the broker's frame parser, authorization engine, AAL log, and router. It is safe to call from any goroutine; concurrency control is handled inside transport.Broker.
Use this when integrating new transports (e.g. internal/webtransport) that ride on top of QUIC bi-di streams without spawning an extra transport.Broker.
func (*Broker) Listen ¶
Listen starts the QUIC listener on the given UDP address with 0-RTT support. tlsConf must contain a valid certificate and set NextProtos.
func (*Broker) ReplayAAL ¶ added in v1.3.0
ReplayAAL replays all historical CmdPublish frames from AAL into the router before socket bind.
func (*Broker) SetAuthzEngine ¶ added in v1.12.0
SetAuthzEngine updates the active authorization engine.
type Option ¶
type Option func(*Broker)
Option configures the Broker.
func WithAALReplay ¶ added in v1.3.0
WithAALReplay enables startup state restoration from an AAL log file.
func WithCompression ¶ added in v1.10.0
func WithCompression(engine broker.CompressionEngine, minBatchSize int) Option
WithCompression enables batch payload decompression for received frames. engine provides ZSTD decompression. minBatchSize is ignored on the receive side (all compressed batches are decompressed regardless of size).
func WithLogger ¶
WithLogger sets a structured logger for the broker.
func WithMaxBufSize ¶
WithMaxBufSize sets the maximum buffer size before the processor falls back to heap allocation. Default: 64KB.
func WithMaxDecompressedPerStream ¶ added in v1.17.0
WithMaxDecompressedPerStream sets the maximum total decompressed bytes per stream before the broker rejects further compressed frames. Default: 16 MB. Prevents a single malicious peer from exhausting memory via compression bombs.
func WithReadBufSize ¶
WithReadBufSize sets the initial read buffer size per stream processor. Must be >= protocol.HeaderSize (10). Default: 1024.
func WithRouter ¶
WithRouter sets the pub/sub router for CmdPublish and CmdSubscribe handling.
func WithTracer ¶ added in v1.9.0
WithTracer sets the OpenTelemetry tracer for distributed tracing.