pass

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pass provides NATS JetStream abstractions for SmokedMeat. In deli terms: The Pass is where the Kitchen places results for pickup.

Index

Constants

View Source
const (
	// DefaultConnectTimeout is the default timeout for connecting to NATS.
	DefaultConnectTimeout = 10 * time.Second

	// DefaultReconnectWait is the default wait time between reconnection attempts.
	DefaultReconnectWait = 2 * time.Second

	// DefaultMaxReconnects is the default maximum number of reconnection attempts.
	DefaultMaxReconnects = 60
)
View Source
const (
	// SubjectOrders is the subject for commands from Counter to Brisket.
	// Format: smokedmeat.orders.<agent_id>
	SubjectOrdersPrefix = "smokedmeat.orders"

	// SubjectColeslaw is the subject for responses from Brisket to Counter.
	// Format: smokedmeat.coleslaw.<agent_id>
	SubjectColeslawPrefix = "smokedmeat.coleslaw"

	// SubjectBeacon is the subject for Brisket heartbeats.
	// Format: smokedmeat.beacon.<agent_id>
	SubjectBeaconPrefix = "smokedmeat.beacon"
)

Subject naming conventions for SmokedMeat.

View Source
const DefaultCallbackTimeout = 30 * time.Second

DefaultCallbackTimeout is the default timeout for consumer callbacks.

Variables

This section is empty.

Functions

func BeaconSubject

func BeaconSubject(agentID string) string

BeaconSubject returns the subject for beacons from a specific agent.

func ColeslawSubject

func ColeslawSubject(agentID string) string

ColeslawSubject returns the subject for responses from a specific agent.

func DefaultStreamConfig

func DefaultStreamConfig() jetstream.StreamConfig

DefaultStreamConfig returns the default stream configuration for SmokedMeat.

func OrdersSubject

func OrdersSubject(agentID string) string

OrdersSubject returns the subject for orders to a specific agent.

Types

type Client

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

Client wraps a NATS connection with JetStream support.

func NewClient

func NewClient(ctx context.Context, config ClientConfig) (*Client, error)

NewClient creates a new NATS client with the given configuration.

func (*Client) Close

func (c *Client) Close()

Close closes the NATS connection.

func (*Client) Conn

func (c *Client) Conn() *nats.Conn

Conn returns the underlying NATS connection.

func (*Client) EnsureStream

func (c *Client) EnsureStream(ctx context.Context, config jetstream.StreamConfig) (jetstream.Stream, error)

EnsureStream creates or updates a JetStream stream.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client is connected to NATS.

func (*Client) JetStream

func (c *Client) JetStream() jetstream.JetStream

JetStream returns the underlying JetStream context.

type ClientConfig

type ClientConfig struct {
	URL            string
	Name           string
	ConnectTimeout time.Duration
	ReconnectWait  time.Duration
	MaxReconnects  int
}

ClientConfig holds configuration for the NATS client.

func DefaultConfig

func DefaultConfig(url string) ClientConfig

DefaultConfig returns a ClientConfig with sensible defaults.

type Consumer

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

Consumer consumes messages from NATS JetStream subjects.

func NewConsumer

func NewConsumer(ctx context.Context, client *Client, config ConsumerConfig) (*Consumer, error)

NewConsumer creates a new Consumer for a given stream and subject filter.

func (*Consumer) ConsumeWithTimeout

func (c *Consumer) ConsumeWithTimeout(timeout time.Duration, handler func(ctx context.Context, msg jetstream.Msg)) (jetstream.ConsumeContext, error)

ConsumeWithTimeout starts consuming messages with a timeout-protected callback. If the handler doesn't complete within the timeout, the message is NAKed and an error is logged. This prevents hung callbacks from blocking the consumer.

type ConsumerConfig

type ConsumerConfig struct {
	StreamName    string
	ConsumerName  string
	FilterSubject string
	Durable       bool
}

ConsumerConfig holds configuration for creating a consumer.

type Publisher

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

Publisher publishes messages to NATS JetStream subjects.

func NewPublisher

func NewPublisher(client *Client) *Publisher

NewPublisher creates a new Publisher.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, subject string, data []byte) error

Publish publishes a message to the given subject.

func (*Publisher) PublishAsync

func (p *Publisher) PublishAsync(subject string, data []byte) (jetstream.PubAckFuture, error)

PublishAsync publishes a message asynchronously.

func (*Publisher) PublishBeacon

func (p *Publisher) PublishBeacon(ctx context.Context, agentID string, data []byte) error

PublishBeacon publishes a heartbeat from a specific agent.

func (*Publisher) PublishColeslaw

func (p *Publisher) PublishColeslaw(ctx context.Context, agentID string, data []byte) error

PublishColeslaw publishes a response from a specific agent.

func (*Publisher) PublishOrder

func (p *Publisher) PublishOrder(ctx context.Context, agentID string, data []byte) error

PublishOrder publishes an order to a specific agent.

Jump to

Keyboard shortcuts

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