nats

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package nats profiles core NATS publish and subscription handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Publish sends payload to subject.
	Publish(string, []byte) error
	// PublishMsg sends a prepared NATS message.
	PublishMsg(*nats.Msg) error
	// Subscribe registers a handler for subject.
	Subscribe(string, nats.MsgHandler) (*nats.Subscription, error)
	// QueueSubscribe registers a queue-group handler for subject.
	QueueSubscribe(string, string, nats.MsgHandler) (*nats.Subscription, error)
}

Client is the core NATS API wrapped by Profile. Retain the original *nats.Conn for lifecycle and APIs outside this focused interface.

type Config

type Config struct {
	Connection     string
	CapturePayload bool
	PayloadLimit   int
}

Config controls NATS metadata and optional bounded payload capture.

type ProfiledClient

type ProfiledClient interface {
	Client
	// PublishContext publishes while correlating the dispatch with ctx.
	PublishContext(context.Context, string, []byte) error
}

ProfiledClient adds a context-aware publish operation for request correlation while preserving the wrapped core NATS API.

func Profile

func Profile(client Client, configs ...Config) ProfiledClient

Profile wraps client with the default profiler. It returns nil for a nil client and otherwise preserves core NATS operations.

func ProfileWith

func ProfileWith(p *webpprof.Profiler, client Client, configs ...Config) ProfiledClient

ProfileWith wraps client with p. When p is nil, operations still delegate to client but no entries are recorded.

Jump to

Keyboard shortcuts

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