nats

package
v1.4.26 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

Regarding the distribution of stream creation across nodes in a NATS JetStream cluster, NATS JetStream does not directly provide a load balancing feature to evenly distribute streams among different nodes. The creation and management of streams mainly depend on the client and configuration, and you need to implement load balancing at the application layer.

To achieve load balancing for stream creation in a NATS JetStream cluster, you can adopt the following strategies:

  1. Client-side Load Balancing: In your client application, you can choose which NATS server to connect to when creating a stream. You can implement a simple strategy, such as round-robin or random selection, to create streams on different NATS nodes. This approach requires you to manage node selection logic within your application code.

  2. Using a Proxy or Load Balancer: Deploy a proxy or load balancer, such as HAProxy, Envoy, or Nginx, in front of your NATS cluster. Configure the proxy or load balancer to distribute client requests to different NATS nodes. In this way, when clients create streams, the proxy or load balancer will automatically distribute the requests to different nodes.

Both of these methods require implementing load balancing logic at the application or infrastructure layer. Note that the load balancing here focuses on stream creation across different nodes, rather than replication of stream data. Data replication is still achieved by the high-availability features of NATS JetStream (by setting the number of replicas).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Nats

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

func New

func New() *Nats

func (*Nats) Close

func (n *Nats) Close()

func (*Nats) Connect

func (n *Nats) Connect(url string) (err error)

func (*Nats) Flush

func (n *Nats) Flush() error

func (*Nats) Pub

func (n *Nats) Pub(subj string, data []byte) error

func (*Nats) Req

func (n *Nats) Req(subj string, data []byte) ([]byte, error)

func (*Nats) SubASync

func (n *Nats) SubASync(subject string, callback func(data []byte)) (err error)

func (*Nats) SubSync

func (n *Nats) SubSync(subject string) ([]byte, error)

func (*Nats) UnSub

func (n *Nats) UnSub(subject string, drained bool) (err error)

type SubInfo

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

Jump to

Keyboard shortcuts

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