Skip to content

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

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.