nats

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMarshalError     = errors.New("MARSHAL_ERROR")
	ErrUnmarshalError   = errors.New("UNMARSHAL_ERROR")
	ErrNotConnected     = errors.New("not connected to nats")
	ErrHostIsNotDefined = errors.New("NATS_HOST environment is required")

	TotalWait      time.Duration = 3 * time.Minute
	ReconnectDelay time.Duration = 10 * time.Second
)

Functions

This section is empty.

Types

type Client

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

func New

func New(ctx context.Context) (*Client, error)

New open a new nats connection, and start a listening for the requests.

func (*Client) Handler

func (c *Client) Handler(pattern string, h Handler)

Handle adds the route `pattern` that matches any method to execute the `handler` Handler.

func (*Client) Publish added in v0.3.8

func (c *Client) Publish(sub string, b []byte) error

Publish a message to nats

func (*Client) Request added in v0.3.3

func (c *Client) Request(sub string, b []byte, timeout time.Duration) (*types.Message, error)

Make a nats request. Accept a byte array, return a types.Message.

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown will close the nats.io connection.

type Handler

type Handler func(r *Request)

type Request

type Request struct {
	Message *types.Message
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest() *Request

func (*Request) AddTags

func (r *Request) AddTags(tags ...string)

send a message to gateway on session.tag, and AddTags in body

func (*Request) Context added in v0.3.1

func (r *Request) Context() context.Context

returns a request context

func (*Request) Error

func (r *Request) Error(code error, message error) error

send a error with code and message

func (*Request) Original

func (r *Request) Original() *nats.Msg

returns an origin nats.Msg

func (*Request) Publish

func (r *Request) Publish(sub string, b []byte) error

allows to publish something to some channel

func (*Request) RemoveTags

func (r *Request) RemoveTags(tags ...string)

send a message to gateway on session.tag, and RemoveTags in body

func (*Request) RemoveTagsByPrefix added in v0.3.7

func (r *Request) RemoveTagsByPrefix(tags ...string)

send a message to gateway on session.tag, and RemoveByPrefix in body

func (*Request) Respond

func (r *Request) Respond(data interface{}) error

send a response wit data

func (*Request) UnmarshalBody added in v0.3.4

func (r *Request) UnmarshalBody(dest interface{}) error

allows to unmarshal body to provided structure

type RequestPool

type RequestPool struct {
	sync.Pool
}

func NewResponsePool

func NewResponsePool() RequestPool

func (*RequestPool) GetResponse

func (r *RequestPool) GetResponse() *Request

func (*RequestPool) PutResponse

func (r *RequestPool) PutResponse(res *Request)

Jump to

Keyboard shortcuts

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