natsbroker

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package natsbroker provides a NATS adapter for runtime/contracts.

Index

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 publishes contract events to a NATS subject and can receive them from a synchronous subscription. It implements contracts.Broker and contracts.EventSource.

func New

func New(conn *nats.Conn, subject string, options ...Option) *Broker

New creates a NATS broker adapter.

func (*Broker) Close

func (broker *Broker) Close() error

Close unsubscribes the receive subscription.

func (*Broker) PublishEvents

func (broker *Broker) PublishEvents(ctx context.Context, events []contracts.EventEnvelope) error

PublishEvents publishes event envelopes to the configured subject.

func (*Broker) ReceiveEventBatch

func (broker *Broker) ReceiveEventBatch(ctx context.Context) (contracts.EventBatch, error)

ReceiveEventBatch receives up to the configured batch size. Core NATS acknowledgements are implicit, so returned batches do not include ack hooks.

type Decoder

type Decoder func(json.RawMessage) (any, error)

Decoder converts one JSON event value into the typed value expected by runtime/contracts subscribers.

type Option

type Option func(*Broker)

Option configures a Broker.

func WithBatchSize

func WithBatchSize(size int) Option

WithBatchSize sets the max messages returned per receive call.

func WithDecoder

func WithDecoder(eventType string, decoder Decoder) Option

WithDecoder registers a decoder for one event type.

func WithJSONDecoder

func WithJSONDecoder[T any](eventType string) Option

WithJSONDecoder registers a JSON decoder for one event type.

func WithQueue

func WithQueue(queue string) Option

WithQueue sets an optional queue group for subscribers.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the max wait for one message.

Jump to

Keyboard shortcuts

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