nats

package
v0.0.0-...-0490640 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

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

	HabServiceEventCh  chan *applications.HabService // TODO: @afiune make a pipeline instead
	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, subject 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 *applications.HabService) 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() 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) PublishHabService

func (nc *NatsClient) PublishHabService(msg *applications.HabService) error

PublishHabService publishes a HabService message to the NATS server

Usage: ```

msg := &applications.HabService{
  SupervisorId: "asdfg1234qwer5678",
  Group:        "default",
  PkgIdent:     &applications.PackageIdent{
    Origin:  "core",
    Name:    "redis",
    Version: "0.1.0",
    Release: "20190101121212",
  },
}

client.PublishHabService(msg) ```

func (*NatsClient) Subscribe

func (nc *NatsClient) Subscribe() (stan.Subscription, error)

Jump to

Keyboard shortcuts

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