Documentation ¶
Index ¶
- Constants
- Variables
- func WithLogger(logger logger.Logger) func(*NatsConnector)
- type NATS
- type NatsConnector
- func (nc *NatsConnector) Disconnect() error
- func (nc *NatsConnector) Publish(event models.KeptnContextExtendedCE) error
- func (nc *NatsConnector) QueueSubscribe(subject string, queueGroup string, fn ProcessEventFn) error
- func (nc *NatsConnector) QueueSubscribeMultiple(subjects []string, queueGroup string, fn ProcessEventFn) error
- func (nc *NatsConnector) Subscribe(subject string, fn ProcessEventFn) error
- func (nc *NatsConnector) SubscribeMultiple(subjects []string, fn ProcessEventFn) error
- func (nc *NatsConnector) UnsubscribeAll() error
- type ProcessEventFn
Constants ¶
const ( EnvVarNatsURL = "NATS_URL" EnvVarNatsURLDefault = "nats://keptn-nats" CloudEventsVersionV1 = "1.0" )
Variables ¶
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