Documentation
¶
Overview ¶
Package consul keeps a service present in Consul: manifest per version, instance state under a TTL session (it disappears with the instance) and the catalog registration. The state is published from before the author's tree starts (phase starting) so a service waiting for its dependencies is visible; the catalog registration follows only once it serves. Consul being absent never fails the service.
Index ¶
Constants ¶
const BackplaneService = "backplane"
BackplaneService is the service name backplane runs under.
Variables ¶
var ( // ErrStateHeld: the instance state key is locked by a session that is // not an incarnation of this instance, or is still in its lock delay. ErrStateHeld = errors.New("consul: instance state held") // ErrDuplicateInstance: another live process runs with this instance id. ErrDuplicateInstance = errors.New("consul: duplicate instance id") // ErrManifestConflict: this version already has different declarations. ErrManifestConflict = errors.New("consul: different manifest already published for this version") )
Functions ¶
This section is empty.
Types ¶
type Check ¶
Check is the catalog registration's health check; zero fields take the defaults (10s, 5s, 1m).
type ConfigState ¶
ConfigState is the dynamic configuration seen by the presence.
type Discovery ¶ added in v0.3.0
type Discovery struct {
// contains filtered or unexported fields
}
Discovery finds backplane's replicas: the instance states the SDK of each one writes to KV (phase serving, with a platform port), as the registry reads them. Lists are cached for a few seconds.
func NewDiscovery ¶ added in v0.3.0
NewDiscovery creates the discovery over client.
type Identity ¶
type Identity struct {
Service string
Version string
Instance string
Address string
PlatformPort uint16
PublicPort uint16 // 0 when the service has no managed public routes
Commit string
}
Identity is how the instance presents itself.
type Params ¶
type Params struct {
Client *api.Client
Log *xlog.Logger
Identity Identity
Manifest *backplanev1.Manifest
// Register in the catalog; false when the deployment registers.
Register bool
// Tags of the catalog registration.
Tags []string
Check Check
// SessionTTL of the session holding the instance state; 0 is 30s,
// clamped to Consul's 10s..24h. Renewed every TTL/3; renewals failing
// for TTL/2 re-establish the presence.
SessionTTL time.Duration
// Config may be nil.
Config ConfigState
// Nodes reports the author's dependencies; may be nil. Read on every
// state write and renew tick: a change is published within a renew
// interval, or at once after Changed.
Nodes func() []*backplanev1.NodeStatus
// Transports reports NATS, Temporal and OTLP; may be nil. Consul is
// added by the presence itself. Read like Nodes.
Transports func() []*backplanev1.TransportStatus
}
Params of New.
type Presence ¶
type Presence struct {
// contains filtered or unexported fields
}
Presence is a lifecycle component.
func (*Presence) Changed ¶
func (p *Presence) Changed()
Changed republishes the state now: nodes or transports changed.
func (*Presence) Deregister ¶
Deregister marks the instance stopping: it leaves the catalog at once and the state says so, while the session and the state live on until Stop. Call it when the instance stops taking traffic. Best effort: Consul errors are logged.
func (*Presence) Register ¶
Register marks the instance serving: the state says so and the loop registers in the catalog (when the SDK registers), retrying in the background. Call it when the instance takes traffic.