nats

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 Imported by: 0

README

nats

The NATS binding for essessey: a Sink that publishes Event.Data raw to subjectPrefix.<event type>, and a Source whose Deliver method you wire in as a subscription callback. It never imports a NATS client; *nats.Conn already satisfies the one-method Publisher interface.

The event id is not carried on this binding.

Full documentation, including the subject scheme and the ordering caveats: NATS binding.

Documentation

Overview

Package nats provides essessey.Sink and essessey.Source bindings for NATS.

NATS is message-oriented: every publish is already a discrete message, so this package needs no SSE-style framing — that framing exists only because an HTTP body is an undelimited byte stream. Sink publishes essessey.Event.Data raw; Source hands events back exactly as they were delivered.

This package deliberately does NOT import github.com/nats-io/nats.go. Publisher declares the one method (Publish(subject string, data []byte) error) this package actually needs, and *nats.Conn already satisfies it structurally — the caller passes their own client, and essessey adds zero transport dependency. This is a design choice, not a missing feature: pulling in the real client would tie essessey's module graph to one NATS driver version for the sake of a single method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Publisher

type Publisher interface {
	Publish(subject string, data []byte) error
}

Publisher is the minimal capability this package needs from a NATS client: publish raw bytes to a subject.

*nats.Conn (github.com/nats-io/nats.go) satisfies this method as-is. Callers pass their own connection — see the package doc comment for why this package never imports the nats client library itself.

type Sink

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

Sink publishes essessey events to NATS subjects.

NATS already delimits messages, so Emit publishes ev.Data RAW — no SSE-style framing. The subject is the configured prefix plus the event's type, so a subscriber can filter with a NATS wildcard subject (subjectPrefix.*) without inspecting payloads.

A real *nats.Conn is safe for concurrent Publish calls, so Emit needs no mutex of its own — it holds no other mutable state.

func NewSink

func NewSink(p Publisher, subjectPrefix string) *Sink

NewSink returns a Sink that publishes through p, with subjects prefixed by subjectPrefix. An empty subjectPrefix publishes to the bare event type.

func (*Sink) Emit

func (s *Sink) Emit(ctx context.Context, ev essessey.Event) error

Emit publishes ev.Data, unframed, to the subject derived from the configured prefix and ev.Event.

type Source

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

Source turns a NATS subscription's push-callback delivery into an essessey.Source. Wire Deliver as the subscription callback; Next pulls events off in the order they arrived.

func NewSource

func NewSource() *Source

NewSource returns a ready-to-use Source.

func (*Source) Close

func (s *Source) Close()

Close stops the source. Next drains any already-buffered events first, then returns essessey.ErrNoMoreEvents. Close is idempotent.

func (*Source) Deliver

func (s *Source) Deliver(ev essessey.Event)

Deliver pushes ev onto the queue for Next to pick up. Deliver after Close is a no-op — the source has already stopped accepting events.

func (*Source) Next

func (s *Source) Next(ctx context.Context) (essessey.Event, error)

Next blocks until an event is delivered, the source is closed and drained, or ctx is done.

Jump to

Keyboard shortcuts

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