nats

package
v0.0.0-...-d983439 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NatsClient

type NatsClient struct {
	certs.TLSConfig

	InsecureSkipVerify bool
	DisableTLS         bool
	// contains filtered or unexported fields
}

The subject is the topic this subscriber will be listening to, right now we will hardcode this value but in the future it could be configurable.

Additionally, we could scope our messages into streams or topics. For example:

* habitat - top level subject to enclose all habitat messages * habitat.service - messages about service events * habitat.supervisor - messages about supervisor events

With this subjects we could define boilerplate messages and have services subscribe to specific topics of interest.

TODO @afiune Make a proposal with diagrams to explain this

func New

func New(url, cluster, client, durable string, tlsConfig certs.TLSConfig) *NatsClient

New creates a new client struct with some defaults

func NewAndConnect

func NewAndConnect(url, id string, tlsConfig certs.TLSConfig) (*NatsClient, error)

NewAndConnect creates a new client struct and connects to the NATS Server

func NewDefaults

func NewDefaults(url, id string, tlsConfig certs.TLSConfig) *NatsClient

NewDefaults creates a new client struct with some defaults

func NewExternalClient

func NewExternalClient(url, cluster, client, durable, subject string) *NatsClient

func (*NatsClient) Close

func (nc *NatsClient) Close()

Close closes the NATS streaming connection and then the underlying raw NATS connection. Since we have to create the raw NATS connection manually in order to configure TLS, we are responsible for closing it.

func (*NatsClient) Connect

func (nc *NatsClient) Connect() error

Connect tries to connect and retries until the maximun time configured perhaps in the future when this is not beta we don't exit after a number of retries and instead continue until we succeed. (when the server is up)

func (*NatsClient) ConnectAndPublish

func (nc *NatsClient) ConnectAndPublish(msg *habitat.HealthCheckEvent) error

ConnectAndPublish will attempt to connect to the NATS Server and then publish a message to the subject that the client was configured

func (*NatsClient) ConnectAndSubscribe

func (nc *NatsClient) ConnectAndSubscribe(eventsCh chan<- []byte) error

ConnectAndSubscribe will attempt to connect to the NATS Server and then subscribe to the subject that the client was configured

func (*NatsClient) PublishBytes

func (nc *NatsClient) PublishBytes(b []byte) error

PublishBytes publishes an array of bytes to the NATS server

Usage: ``` msg := []byte("Here is my message...") client.PublishBytes(msg) ```

func (*NatsClient) PublishHabEvent

func (nc *NatsClient) PublishHabEvent(msg *habitat.HealthCheckEvent) error

PublishHabEvent publishes a Habitat event message to the NATS server

Usage: ``` msg := &habitat.HealthCheckEvent{} client.PublishHabEvent(msg) ```

func (*NatsClient) Subscribe

func (nc *NatsClient) Subscribe(eventsCh chan<- []byte) error

Jump to

Keyboard shortcuts

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