natsutils

package
v0.0.0-...-48c6f6e Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NatsProvider

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

NatsProvider encapsulates a NATS connection, providing methods for publishing messages, subscribing to subjects, and managing connection cleanup.

func NewProvider

func NewProvider(natsConn *nats.Conn) *NatsProvider

NewProvider initializes and returns a new Provider instance with the given NATS connection.

func (*NatsProvider) Cleanup

func (prov *NatsProvider) Cleanup() error

Cleanup gracefully drains and closes the NATS connection, ensuring that all pending messages are sent and resources are released.

func (*NatsProvider) Publish

func (prov *NatsProvider) Publish(subj string, data []byte) error

Publish publishes the data argument to the given subject.

func (*NatsProvider) QueueSubscribe

func (prov *NatsProvider) QueueSubscribe(subj string, queue string, handler nats.MsgHandler) (*nats.Subscription, error)

Subscribe creates an asynchronous queue subscriber on the given subject and queue.

type Provider

type Provider interface {
	Cleanup() error                                                                                // Cleanup gracefully shuts down the provider.
	Publish(subj string, data []byte) error                                                        // Publish sends a message to the specified subject.
	QueueSubscribe(subj string, queue string, handler nats.MsgHandler) (*nats.Subscription, error) // QueueSubscribe subscribes to a subject with a queue group.
}

Provider interface defines the basic operations that can be performed with NATS, such as publishing, subscribing, and cleaning up resources.

Jump to

Keyboard shortcuts

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