nats

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	EnvVarNatsURL        = "NATS_URL"
	EnvVarNatsURLDefault = "nats://keptn-nats"
	CloudEventsVersionV1 = "1.0"
)

Variables

View Source
var (
	ErrSubAlreadySubscribed   = errors.New("already subscribed")
	ErrSubNilMessageProcessor = errors.New("message processor is nil")
	ErrSubEmptySubject        = errors.New("empty subject")
	ErrPubEventTypeMissing    = errors.New("event is missing the event type")
)

Functions

func WithLogger

func WithLogger(logger logger.Logger) func(*NatsConnector)

WithLogger sets the logger to use

Types

type NATS

type NATS interface {
	Subscribe(subject string, fn ProcessEventFn) error
	QueueSubscribe(queueGroup string, subject string, fn ProcessEventFn) error
	SubscribeMultiple(subjects []string, fn ProcessEventFn) error
	QueueSubscribeMultiple(subjects []string, queueGroup string, fn ProcessEventFn) error
	Publish(event models.KeptnContextExtendedCE) error
	Disconnect() error
	UnsubscribeAll() error
}

type NatsConnector

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

NatsConnector can be used to subscribe to certain events on the NATS event system

func New

func New(connectURL string, opts ...func(connector *NatsConnector)) *NatsConnector

New returns an initialised NatsConnector with a nil connection

func NewFromEnv

func NewFromEnv() *NatsConnector

NewFromEnv returns a NatsConnector to NATS. The URL is read from the environment variable "NATS_URL" If the URL is not set via the environment variable "NATS_URL", it falls back to the default URL "nats://keptn-nats"

func (*NatsConnector) Disconnect

func (nc *NatsConnector) Disconnect() error

Disconnect disconnects/closes the connection to NATS

func (*NatsConnector) Publish

func (nc *NatsConnector) Publish(event models.KeptnContextExtendedCE) error

Publish sends a keptn event to the message broker

func (*NatsConnector) QueueSubscribe

func (nc *NatsConnector) QueueSubscribe(subject string, queueGroup string, fn ProcessEventFn) error

QueueSubscribe adds a queue subscription to the NatsConnector

func (*NatsConnector) QueueSubscribeMultiple

func (nc *NatsConnector) QueueSubscribeMultiple(subjects []string, queueGroup string, fn ProcessEventFn) error

QueueSubscribeMultiple adds multiple queue subscriptions to the NatsConnector

func (*NatsConnector) Subscribe

func (nc *NatsConnector) Subscribe(subject string, fn ProcessEventFn) error

Subscribe adds a subscription to a specific subject to the NatsConnector. It takes the subject as string (usually the event type) and a function fn being called when an event is received

func (*NatsConnector) SubscribeMultiple

func (nc *NatsConnector) SubscribeMultiple(subjects []string, fn ProcessEventFn) error

SubscribeMultiple adds multiple subscriptions to the NatsConnector

func (*NatsConnector) UnsubscribeAll

func (nc *NatsConnector) UnsubscribeAll() error

UnsubscribeAll deletes all current subscriptions

type ProcessEventFn

type ProcessEventFn func(msg *nats.Msg) error

ProcessEventFn is used to process a received keptn event

Jump to

Keyboard shortcuts

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