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
- func BeaconSubject(agentID string) string
- func ColeslawSubject(agentID string) string
- func DefaultStreamConfig() jetstream.StreamConfig
- func OrdersSubject(agentID string) string
- type Client
- type ClientConfig
- type Consumer
- type ConsumerConfig
- type Publisher
- func (p *Publisher) Publish(ctx context.Context, subject string, data []byte) error
- func (p *Publisher) PublishAsync(subject string, data []byte) (jetstream.PubAckFuture, error)
- func (p *Publisher) PublishBeacon(ctx context.Context, agentID string, data []byte) error
- func (p *Publisher) PublishColeslaw(ctx context.Context, agentID string, data []byte) error
- func (p *Publisher) PublishOrder(ctx context.Context, agentID string, data []byte) error
Constants ¶
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 )
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.
const DefaultCallbackTimeout = 30 * time.Second
DefaultCallbackTimeout is the default timeout for consumer callbacks.
Variables ¶
This section is empty.
Functions ¶
func BeaconSubject ¶
BeaconSubject returns the subject for beacons from a specific agent.
func ColeslawSubject ¶
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 ¶
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) EnsureStream ¶
func (c *Client) EnsureStream(ctx context.Context, config jetstream.StreamConfig) (jetstream.Stream, error)
EnsureStream creates or updates a JetStream stream.
func (*Client) IsConnected ¶
IsConnected returns true if the client is connected to NATS.
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 ¶
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 ¶
NewPublisher creates a new Publisher.
func (*Publisher) PublishAsync ¶
PublishAsync publishes a message asynchronously.
func (*Publisher) PublishBeacon ¶
PublishBeacon publishes a heartbeat from a specific agent.
func (*Publisher) PublishColeslaw ¶
PublishColeslaw publishes a response from a specific agent.