natsio

package module
v1.0.3 Latest Latest
Warning

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

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

README

message broker with nats.io

Message broker

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientRequest

func ClientRequest[REQUEST any, RESPONSE any](subject string, req REQUEST) (RESPONSE, error)

ClientRequest ...

func Connect

func Connect(cfg Config) error

Connect ...

func ConvertData

func ConvertData[T any](data []byte) T

ConvertData ...

func GetConn

func GetConn() *nats.Conn

GetConn ...

func IsDisconnected

func IsDisconnected()

func Publish

func Publish(sub string, payload []byte) error

func PublishRequest

func PublishRequest(sub, reply string, data []byte) error

func QueueSubscribe

func QueueSubscribe(subject, queue string, cb nats.MsgHandler)

QueueSubscribe ...

func Reply

func Reply(msg *nats.Msg, payload []byte) error

Reply ...

func Request

func Request(subject string, payload []byte) (*nats.Msg, error)

Request ...

func Response

func Response(msg *nats.Msg, payload interface{}, message string) error

Response ...

func ToBytes

func ToBytes(data interface{}) []byte

ToBytes ...

Types

type Config

type Config struct {
	// Connect url
	URL string

	// Auth user
	User string

	// Auth password
	Password string

	// TLS config
	TLS *TLSConfig

	// RequestTimeout
	RequestTimeout time.Duration

	Debug bool
}

Config ...

func GetConfig

func GetConfig() Config

GetConfig ...

type MethodHandle

type MethodHandle func(queue interface{}) nats.MsgHandler

type NatsResponse

type NatsResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Data    []byte `json:"data"`
}

NatsResponse ..

type QueueDesc

type QueueDesc struct {
	Subject string
	Worker  string
	Handle  MethodHandle
}

func (QueueDesc) GetSubject

func (q QueueDesc) GetSubject(serverName string) string

GetSubject get subject for nats request

type ServiceDesc

type ServiceDesc struct {
	Queues []QueueDesc
}

func (ServiceDesc) Register

func (s ServiceDesc) Register(queue interface{}) error

Register callback handler

type TLSConfig

type TLSConfig struct {
	// Cert file
	CertFilePath string

	// Key file
	KeyFilePath string

	// Root CA
	RootCAFilePath string
}

TLSConfig ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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