Documentation
¶
Overview ¶
Package nats adapts core NATS publish/subscribe to transport/message.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Publish(ctx context.Context, subject string, msg *message.Message) error
- func (c *Client) Request(ctx context.Context, subject string, msg *message.Message) (*message.Message, error)
- func (c *Client) Subscribe(ctx context.Context, subject string, handler message.Handler) (message.Subscription, error)
- type ErrorHandler
- type Option
Constants ¶
const ( // HeaderMessageID carries message.Message.ID through core NATS headers. HeaderMessageID = "forge-message-id" // HeaderMessageKey carries message.Message.Key through core NATS headers. HeaderMessageKey = "forge-message-key" )
Variables ¶
var ( // ErrNilContext reports an operation started without a context. ErrNilContext = errors.New("nats: nil context") // ErrEmptySubject reports an invalid NATS subject. ErrEmptySubject = errors.New("nats: empty subject") // ErrEmptyURL reports an invalid NATS server URL. ErrEmptyURL = errors.New("nats: empty url") // ErrNilMessage reports an invalid message. ErrNilMessage = errors.New("nats: nil message") // ErrNilHandler reports an invalid subscription handler. ErrNilHandler = errors.New("nats: nil handler") // ErrNilConn reports an invalid connection option. ErrNilConn = errors.New("nats: nil connection") // ErrClosed reports an adapter closed by its owner. ErrClosed = errors.New("nats: client closed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client adapts one NATS connection to Forge message transport.
func New ¶
New creates a NATS message adapter. Without WithConn, the returned client owns the connection and closes it from Close.
func (*Client) Close ¶
Close closes an adapter-owned connection. Application-owned connections supplied with WithConn are left open.
func (*Client) Publish ¶
Publish sends one core NATS message and flushes the connection with the caller's context. A successful return means the server responded to the flush after the publish; it does not imply durable JetStream storage.
type ErrorHandler ¶
ErrorHandler observes handler failures from asynchronous NATS callbacks. Core NATS has no acknowledgement decision to return to the server, so the adapter reports the error to the application instead of logging globally. Different subscriptions may call the handler concurrently.
type Option ¶
type Option func(*options)
Option configures a Client.
func WithConn ¶
WithConn uses an application-owned NATS connection. Client.Close will not close a connection supplied this way.
func WithConnectOptions ¶
WithConnectOptions appends options used by nats.Connect.
func WithErrorHandler ¶
func WithErrorHandler(handler ErrorHandler) Option
WithErrorHandler observes asynchronous handler failures.
func WithFlushTimeout ¶
WithFlushTimeout sets the default FlushWithContext deadline used by Publish and Subscribe when the caller's context has no deadline. A non-positive value leaves the caller's context unchanged.