nats

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithoutJetstream

func WithoutJetstream(nc *NatsConnection)

Types

type NatsConnection

type NatsConnection struct {
	HostName     string
	Port         string
	UseJetstream bool

	Conn *nats.Conn
	JS   jetstream.JetStream
	// contains filtered or unexported fields
}

func DefaultNatsConnection

func DefaultNatsConnection() *NatsConnection

func New

func New(optFuncs ...NatsConnectionOption) *NatsConnection

func (*NatsConnection) AddEventSub

func (n *NatsConnection) AddEventSub(t TopicType, entityId string, handler func(ha.EventData) error) (*nats.Subscription, error)

AddEventSub: Add a subscriber to the NATS client that receives the full event payload

func (*NatsConnection) AddRawSub

func (n *NatsConnection) AddRawSub(t TopicType, entityId string, handler func([]byte) error) (*nats.Subscription, error)

AddEventSub: Add a subscriber to the NATS client that receives the raw event payload in bytes

func (*NatsConnection) AddStateSub

func (n *NatsConnection) AddStateSub(t TopicType, entityId string, handler func(ha.StateData) error) (*nats.Subscription, error)

AddStateSub: Add a subscriber to the NATS client that receives the new state payload from an event

func (*NatsConnection) AddSub

func (n *NatsConnection) AddSub(t TopicType, entityId string, handler func() error) (*nats.Subscription, error)

AddSub: Add a subscriber to the NATS client that doesn't receive any data from the event

func (*NatsConnection) Close

func (n *NatsConnection) Close()

func (*NatsConnection) Connect

func (n *NatsConnection) Connect() error

func (*NatsConnection) Publish

func (n *NatsConnection) Publish(ctx context.Context, subject string, payload []byte, opts ...jetstream.PublishOpt)

func (*NatsConnection) Stream

func (n *NatsConnection) Stream(ctx context.Context, subject string) (stream jetstream.Stream, consumer jetstream.Consumer, err error)

func (*NatsConnection) Subscribe

func (n *NatsConnection) Subscribe(subject string) (sub *nats.Subscription, ch chan *nats.Msg, err error)

type NatsConnectionOption

type NatsConnectionOption func(*NatsConnection)

func WithClientName

func WithClientName(name string) NatsConnectionOption

func WithConnectionOption

func WithConnectionOption(opt nats.Option) NatsConnectionOption

func WithHostName

func WithHostName(hostname string) NatsConnectionOption

func WithJetstreamnOption

func WithJetstreamnOption(opt jetstream.JetStreamOpt) NatsConnectionOption

func WithLogger

func WithLogger(logger *slog.Logger) NatsConnectionOption

func WithPort

func WithPort(port string) NatsConnectionOption

func WithToken

func WithToken(token string) NatsConnectionOption

type TopicType

type TopicType string
const AttributeTopicType TopicType = "attributes"
const CommandTopicType TopicType = "command"
const NfcTopicType TopicType = "nfc"
const ScheduleTopicType TopicType = "schedules"
const StateTopicType TopicType = "states"
const TimerTopicType TopicType = "timers"
const ZhaTopicType TopicType = "zha"
const ZwaveSceneTopicType TopicType = "zwave-scene"
const ZwaveTopicType TopicType = "zwave"

func (TopicType) GetTopic

func (t TopicType) GetTopic(id string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳