pubsub

package
v0.0.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any) []byte

Marshal marshals the given value to a JSON byte slice

Types

type Broker

type Broker interface {
	Publish(subject string, message []byte, msgID ...string) error
	Subscribe(subject string, group string, handler func([]byte) ([]byte, error)) error
	CreateStream(streamName, subject string, dedupWindow time.Duration) error
}

Broker is the interface that wraps the methods for a message broker

type NATSBroker

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

NATSBroker defines the structure of the NATS broker with Redis for deduplication

func MustNewNATSBroker

func MustNewNATSBroker(url string, redisAddr string) *NATSBroker

MustNewNATSBroker creates a new NATS broker and panics if there's an error

func NewNATSBroker

func NewNATSBroker(url string, redisAddr string) (*NATSBroker, error)

NewNATSBroker initializes the NATS broker and the Redis client

func (*NATSBroker) CreateStream

func (n *NATSBroker) CreateStream(streamName, subject string, dedupWindow time.Duration) error

CreateStream creates a new stream with a deduplication window

func (*NATSBroker) Publish

func (n *NATSBroker) Publish(subject string, message []byte, msgID ...string) error

Publish publishes a message to a NATS JetStream subject using the provided msgID for deduplication

func (*NATSBroker) Subscribe

func (n *NATSBroker) Subscribe(subject, group string, handler func([]byte) ([]byte, error)) error

Subscribe subscribes to a NATS JetStream subject with a queue group and manual acknowledgment

Jump to

Keyboard shortcuts

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