nats

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeLog       = "dev.cvewatcher.mulval.operation.log"
	TypeSucceeded = "dev.cvewatcher.mulval.operation.succeeded"
	TypeFailed    = "dev.cvewatcher.mulval.operation.failed"
)

Variables

This section is empty.

Functions

func UnmarshalCancel

func UnmarshalCancel(raw []byte) (apiv1.Cancel, error)

Types

type HeaderCarrier

type HeaderCarrier nats.Header

HeaderCarrier adapts nats.Header to the TextMapCarrier interface so OpenTelemetry can inject and extract trace context

func (HeaderCarrier) Get

func (c HeaderCarrier) Get(key string) string

func (HeaderCarrier) Keys

func (c HeaderCarrier) Keys() []string

func (HeaderCarrier) Set

func (c HeaderCarrier) Set(key, value string)

type Manager

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

Manager wraps a NATS connection and JetStream context. It provisions the required streams and KV bucket on first connect and re-provisions on reconnect.

func NewManager

func NewManager(ctx context.Context, config ManagerConfig) (*Manager, error)

func (*Manager) Close

func (m *Manager) Close()

Close drains and closes the underlying NATS connection.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context) error

Connect establishes the NATS connection and provisions streams. Reconnection is handled automatically by the NATS client with callbacks that re-provision streams (idempotent) and update metrics.

func (*Manager) Healthcheck

func (m *Manager) Healthcheck(ctx context.Context) error

Healthcheck verifies the NATS connection and JetStream availability. It checks the connection status and performs a lightweight JetStream API call (AccountInfo)to confirm the server is reachable and JetStream is enabled.* Returns nil if healthy.

func (*Manager) PublishCancel

func (m *Manager) PublishCancel(ctx context.Context, source, opID, reason string) error

PublishCancel wraps a CancelRequest in a CloudEvent and publishes it to the cancel stream with Nats-Msg-Id deduplication.

func (*Manager) PublishOperationUpdate

func (m *Manager) PublishOperationUpdate(
	ctx context.Context,
	opID string,
) error

func (*Manager) SubscribeCancel

func (m *Manager) SubscribeCancel(ctx context.Context, opID string, handler func(req apiv1.Cancel)) error

SubscribeCancel polls the cancel stream for a cancel message, calling handler at most once. Closes automatically when ctx is cancelled.

func (*Manager) SubscribeOperationUpdate

func (m *Manager) SubscribeOperationUpdate(ctx context.Context, opID string) (<-chan jetstream.Msg, func(), error)

type ManagerConfig

type ManagerConfig struct {
	URL        string
	InstanceID string

	Logger  *zap.Logger
	Tracer  trace.Tracer
	Metrics *monitoring.Metrics
}

Jump to

Keyboard shortcuts

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