Scale out using Nats

This section explains aspects of setting up a Nats server for scaling out.

Set up

  1. In the Go import statements add github.com/kataras/neffos/stackexchange/nats and use it.

Use

The first and only required input argument is the URL connection string of the nats server(s). Servers addresses are separated by comma ,. If it's empty then it defaults to "nats://127.0.0.1:4222".

The second one is optional and can be used to register various nats client options, such as authentication, see the available nats.go options.

The nats StackExchange's client configuration defaults to nats.go DefaultOptions.

import "github.com/kataras/neffos/stackexchange/nats"

// [server := neffos.New...]

exc, err := nats.NewStackExchange(":4222")
if err != nil {
	// [...]
}
server.UseStackExchange(exc)

If you use the same nats server instance for multiple neffos apps, set its exc.SubjectPrefix to different values across your apps.

References

Last updated