Documentation
¶
Overview ¶
options package is a package that stores publisher's configuration and has convenience functions to configure it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Codec ¶
type Codec interface {
Encode(nmsg []byte, msg proto.Message) ([]byte, error)
Decode(nmsg []byte, msg proto.Message) error
}
Codec represents a message encoder and decoder
type ContextKeyType ¶
type ContextKeyType string
const ( CancelFuncKey ContextKeyType = "cancel" GroupFuncKey ContextKeyType = "group" )
type NatsConn ¶
type NatsConn interface {
Subscribe(subj string, cb nats.MsgHandler) (*nats.Subscription, error)
QueueSubscribe(subj, queue string, cb nats.MsgHandler) (*nats.Subscription, error)
PublishMsg(m *nats.Msg) error
RequestMsgWithContext(ctx context.Context, msg *nats.Msg) (*nats.Msg, error)
Flush() error
}
type Options ¶
type Options struct {
// The global context
Context context.Context
// The global error group that should be used to start internal goroutines.
// .Close() methods will wait on this group until all goroutines have exited.
// It will cancel the Context if any of the goroutines exit with an error.
Group *errgroup.Group
// Cancel function is used to initiate the shutdown of the service.
Cancel context.CancelCauseFunc
// Include verbose logging
VerboseLog bool
Logger *slog.Logger
// Determines how often to send telemetry messages.
TelemetryPeriod time.Duration
// The size of the publish queue
PublishQueueSize int
// The size of the subscriber's queue
SubscribeQueueSize int
// Publishing NATS connection
PubNats NatsConn
// Subscribing NATS connection
SubNats NatsConn
// Request/Reply NATS connection
ReqNats NatsConn
// The private key for this publisher.
// This key is used to sign the messages and is used to derive the identity.
PrivateKey crypto.PrivateKey
// Identity is used internally by publishers and is generated from the private key
Identity string
// A collection of known public keys from which we are allowed to accept messages from.
KnownPublicKeys map[string]ed25519.PublicKey
// Subject prefix for publishing.
Prefix string
// Name of the NATS queue
QueueName string
// Name of JetStream stream. If an empty string is used, then stream name will be "{prefix}-{name}"
StreamName string
// Name of the publisher
Name string
// Codec is used to marshal published messages to whire format.
// Can also be used to unmarshal received messages.
Codec Codec
// Other generic parameters that can be obtained using generic Param function.
Params map[string]any
}
Options struct used by the publisher. This structure shouldn't be modified by the user, however, it is open for modification if needed.
func (Options) Param ¶
Param will return a parameter if it was stored by the provided key. Otherwise it will return a default(first optional argument) or nil.
func (*Options) Parse ¶
Parse initializes the Options with default values and applies any functional option modifiers. Generally this must be called in `New` function that creates a publisher.
func (*Options) SetContext ¶
Click to show internal directories.
Click to hide internal directories.