messaging

package
v0.0.0-...-3e08555 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NatsAuthMethodUser  = "user"
	NatsAuthMethodToken = "token"
	NatsAuthMethodTLS   = "tls"
)

Variables

This section is empty.

Functions

func AddNatsLogHook

func AddNatsLogHook(nc NatsWriter, log *logrus.Entry, subject string, levels ...logrus.Level)

func ConfigureNatsConnection

func ConfigureNatsConnection(config *NatsConfig, log logrus.FieldLogger) (*nats.Conn, error)

func ConfigureNatsStreaming

func ConfigureNatsStreaming(config *NatsConfig, log logrus.FieldLogger) (stan.Conn, error)

func ConnectToNats

func ConnectToNats(config *NatsConfig, opts ...nats.Option) (*nats.Conn, error)

func ConnectToNatsStreaming

func ConnectToNatsStreaming(nc *nats.Conn, config *NatsConfig, log logrus.FieldLogger) (stan.Conn, error)

func ErrorHandler

func ErrorHandler(log logrus.FieldLogger) nats.Option

func NatsRootCAs

func NatsRootCAs(tlsConf *tls.Config) nats.Option

NatsRootCAs is a NATS helper option to provide the RootCAs pool from a tls.Config struct. If Secure is not already set this will set it as well.

Types

type NatsAuth

type NatsAuth struct {
	Method   string `mapstructure:"method"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
	Token    string `mapstructure:"token"`
}

type NatsClientConfig

type NatsClientConfig struct {
	NatsConfig `mapstructure:",squash"`
	Subject    string `mapstructure:"command_subject"`
	Group      string `mapstructure:"command_group"`

	// StartAt will configure where the client should resume the stream:
	// - `all`: all the messages available
	// - `last`: from where the client left off
	// - `new`: all new messages for the client
	// - `first`: from the first message available (default)
	// - other: if it isn't one of the above fields, it will try and parse the param as a go duration (e.g. 30s, 1h)
	StartAt string `mapstructure:"start_at"`
}

type NatsConfig

type NatsConfig struct {
	TLS           *nconf.TLSConfig `mapstructure:"tls_conf"`
	DiscoveryName string           `mapstructure:"discovery_name" split_words:"true"`
	Servers       []string         `mapstructure:"servers"`
	Auth          NatsAuth         `mapstructure:"auth"`

	// for streaming
	ClusterID string `mapstructure:"cluster_id" split_words:"true"`
	ClientID  string `mapstructure:"client_id" split_words:"true"`
	StartPos  string `mapstructure:"start_pos" split_words:"true"`
}

func (*NatsConfig) Fields

func (c *NatsConfig) Fields() logrus.Fields

func (*NatsConfig) LoadServerNames

func (c *NatsConfig) LoadServerNames() error

func (*NatsConfig) ServerString

func (c *NatsConfig) ServerString() string

ServerString will build the proper string for nats connect

func (*NatsConfig) StartPoint

func (c *NatsConfig) StartPoint() (stan.SubscriptionOption, error)

type NatsHook

type NatsHook struct {
	Formatter logrus.Formatter

	LogLevels []logrus.Level
	// contains filtered or unexported fields
}

NatsHook will emit logs to the subject provided

func NewNatsHook

func NewNatsHook(conn NatsWriter, subject string, levels []logrus.Level) *NatsHook

NewNatsHook will create a logrus hook that will automatically send new info into the channel

func (*NatsHook) AddDynamicField

func (hook *NatsHook) AddDynamicField(key string, generator func() interface{}) *NatsHook

AddDynamicField will call that method on each fire

func (*NatsHook) AddField

func (hook *NatsHook) AddField(key string, value interface{}) *NatsHook

AddField will add a simple value each emission

func (*NatsHook) Fire

func (hook *NatsHook) Fire(entry *logrus.Entry) error

Fire will use the connection and try to send the message to the right destination

func (*NatsHook) Levels

func (hook *NatsHook) Levels() []logrus.Level

Levels will describe what levels the NatsHook is associated with

type NatsWriter

type NatsWriter interface {
	Publish(string, []byte) error
}

Jump to

Keyboard shortcuts

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