nats¶
A service that needs messaging early needs it between two goroutines. A service that needs it later needs it between two clusters. Those are usually two pieces of code written a year apart, and the second one is a rewrite.
NATS makes them the same code. This module makes that an estate convention rather than something each project rediscovers.
Start here¶
-
A server and a client in one process, sending a message, in about twenty lines.
-
Every setting, what it defaults to, and why the default is what it is.
-
Why embedding is not a compromise
The embedded server is the same server. What that means for how far it scales.
-
Read before assuming. The refusals are deliberate and several are load-bearing.
The shape¶
import (
gonats "gitlab.com/phpboyscout/go/nats"
"gitlab.com/phpboyscout/go/nats/client"
"gitlab.com/phpboyscout/go/nats/server"
)
srv, err := server.Register(ctx, "nats", controller, log, gonats.ServerSettings{
InProcessOnly: true,
})
cli, err := client.Connect(ctx, gonats.ClientSettings{Name: "my-service"}, nil,
client.InProcess(srv))
Later, when the broker moves out of the process, the first call goes away and
ClientSettings.URL is set. Everything that publishes or subscribes is untouched.