natsutil

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package natsutil implements nats helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Respond added in v1.2.5

func Respond(msg *nats.Msg, bytes []byte)

Respond responds given bytes

func RespondJSON

func RespondJSON(msg *nats.Msg, v any)

RespondJSON responds given value as marshalled bytes

func RespondJSONErr

func RespondJSONErr(msg *nats.Msg, err error)

RespondJSONErr responds given error value as marshalled bytes

Types

type Client

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

Client implements nats client

func DefaultClient

func DefaultClient() (*Client, error)

DefaultClient returns new client initialized from env variables

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns new client value

func (*Client) Close

func (c *Client) Close() error

Close unsubscribes consumers and closes connections

func (*Client) Publish

func (c *Client) Publish(subj string, data []byte) error

Publish sends byte slice to the given subject

func (*Client) PublishJSON

func (c *Client) PublishJSON(subj string, data interface{}) error

PublishJSON marshalls given pointer destination into JSON and sends to the given subject

func (*Client) QueueSubscribe added in v1.2.7

func (c *Client) QueueSubscribe(subj string, queue string, fn nats.MsgHandler) error

QueueSubscribe subscribes given hander to the given subject

func (*Client) Request

func (c *Client) Request(subj string, v any, timeout time.Duration) (*nats.Msg, error)

Request sends request and returns reply's message

func (*Client) Subscribe

func (c *Client) Subscribe(subj string, fn nats.MsgHandler) error

Subscribe subscribes given hander to the given subject

func (*Client) SubscribeJSON

func (c *Client) SubscribeJSON(subj string, fn nats.Handler) error

SubscribeJSON subscribes given hander to the given subject

type Config

type Config struct {
	Env      envutil.AppEnv
	URL      string
	User     string
	Password string
	Timeout  time.Duration
}

Config defines client configuration

Jump to

Keyboard shortcuts

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