natsio

package
v0.0.0-...-3295dff Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Nats

type Nats struct {
	Opts   *NatsOptions
	EncCon *nats.EncodedConn
}

nats.Options wrapper.

func (*Nats) Publish

func (n *Nats) Publish(subject string, data PayloadWithContext) error

Wrapper for nats Publish function. Needs a payload which has a context object (see PayloadWithContext type) Adds a context if it doesn't exist. Otherwise appends which app and time that this message is being sent at. Adds a traceID if not already there

func (*Nats) PublishRequest

func (n *Nats) PublishRequest(subject string, reply string, data PayloadWithContext) error

Wrapper for nats PublishRequest function with context. Adds a context if it doesn't exist. Otherwise appends which app and time that this message is being sent at. Adds a traceID if not already there

func (*Nats) QueueSubscribe

func (n *Nats) QueueSubscribe(route string, group string, handler nats.Handler) error

Subscribe to queue group and record subscription to routes

func (*Nats) Request

func (n *Nats) Request(subject string, data PayloadWithContext, responsePtr interface{}, timeout time.Duration) error

Wrapper for nats Request function with context. Adds a context if it doesn't exist. Otherwise appends which app and time that this message is being sent at. Adds a traceID if not already there

func (*Nats) Subscribe

func (n *Nats) Subscribe(route string, handler nats.Handler) error

Subscribe and record subscription to routes

func (*Nats) UnsubscribeAll

func (n *Nats) UnsubscribeAll()

Unsubscribe all handlers

type NatsOptions

type NatsOptions struct {
	nats.Options
	// contains filtered or unexported fields
}

Used to create a nats connection. To be used in conjunction with a Nats controller to subscribe routes.

func NewNatsOptions

func NewNatsOptions(optionFuncs ...OptionsFunc) (options *NatsOptions)

Initiating nats with default options and then applies each option func in order on top of that.

func (*NatsOptions) Connect

func (natsOpts *NatsOptions) Connect() (natsObj *Nats, err error)

Start subscribing to subjects/routes.

func (*NatsOptions) GetEncoding

func (n *NatsOptions) GetEncoding() string

func (*NatsOptions) GetRoutes

func (n *NatsOptions) GetRoutes() []*Route

Get slice of Routes

func (*NatsOptions) SetEncoding

func (n *NatsOptions) SetEncoding(enc string)

Set the encoding (json/gob)

type OptionsFunc

type OptionsFunc func(*NatsOptions) error

Function for applying options to NatsOptions in NewNatsOptions Using a function allows for a chain or heirarchy when applying them eg func1 then func2 then func3 Internally allows for default options to be applied first.

type PayloadWithContext

type PayloadWithContext interface {
	proto.Message
	GetContext() *NatsContext
	SetContext(*NatsContext)
}

For use when using nats request/publish/publishrequest wrapper functions

type Route

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

Holds route info including subscription holds route,handler,nats subscripiton and queue group.

func (*Route) GetHandler

func (r *Route) GetHandler() nats.Handler

func (*Route) GetQueueGroup

func (r *Route) GetQueueGroup() string

func (*Route) GetRoute

func (r *Route) GetRoute() string

func (*Route) GetSubscription

func (r *Route) GetSubscription() nats.Handler

Directories

Path Synopsis
A default nats initialization.
A default nats initialization.
Package protobuf is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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