nats

package module
v0.0.0-...-e3220b9 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package nats provide a message broker using NATS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONCodec

type JSONCodec struct{}

func (JSONCodec) Marshal

func (m JSONCodec) Marshal(v interface{}) ([]byte, error)

func (JSONCodec) Unmarshal

func (m JSONCodec) Unmarshal(data []byte, v interface{}) error

type Nats

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

Nats is an implementation of broker.Broker using NATS.

func New

func New(opts ...Option) *Nats

New return a new NATs message broker.

func (*Nats) CheckHealth

func (n *Nats) CheckHealth(ctx context.Context) error

CheckHealth implements health.Checker.

func (*Nats) Close

func (n *Nats) Close(ctx context.Context) error

Close flush in-flight messages and close the underlying connection.

func (*Nats) Open

func (n *Nats) Open(ctx context.Context) error

Open connect to target server.

func (*Nats) Publish

func (n *Nats) Publish(ctx context.Context, topic string, m *broker.Message, opts ...broker.PublishOption) error

Publish implements broker.Broker interface.

func (*Nats) Subscribe

func (n *Nats) Subscribe(ctx context.Context, topic string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error)

Subscribe implements broker.Broker interface.

type Option

type Option func(*Nats)

Option is an optional configuration.

func Address

func Address(addrs string) Option

Address is an option to set target addresses of NATS server. Multiple addresses are separated by comma.

func Codec

func Codec(codec codec) Option

Codec is an option to provide a custom codec.

func Logger

func Logger(logger logger) Option

Logger is an option to provide custom logger.

func Options

func Options(opts ...nats.Option) Option

Options is an option to provide additional nats.Option.

Jump to

Keyboard shortcuts

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