Documentation
¶
Overview ¶
Package discovery provides service disovery.
Index ¶
- Constants
- func SubjectPrefix(prefix string) func(*Agent) error
- type Agent
- func (a *Agent) ConnStateHandler(conn *nats.Conn)
- func (a *Agent) Discover(serviceName string, includeLocal bool) []*ServiceInfo
- func (a *Agent) Register(info *ServiceInfo) error
- func (a *Agent) Start() error
- func (a *Agent) Stop() error
- func (a *Agent) Unregister(info *ServiceInfo) error
- func (a *Agent) Unwatch(serviceName string)
- func (a *Agent) Watch(serviceName string) error
- type Option
- type ServiceInfo
Constants ¶
const DefaultSubjectPrefix = "github.com.hatobitoio.discovery"
DefaultSubjectPrefix is the default subject prefix for messages sent by service discovery agent.
const DefaultUpdateInterval = time.Millisecond * 1000
DefaultUpdateInterval is the default update interval for agents. If an agent does not send an update within expected update interval, other agents will forget about services registered by offending agent. 10% threshold is always added.
Variables ¶
This section is empty.
Functions ¶
func SubjectPrefix ¶
SubjectPrefix is an Option that sets the NATS subject prefix used by the Agent. All agents connected to the same NATS server (or servers in same NATS cluster) and using same subject prefix will share the knowledge about available services.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is a service discovery agent.
func (*Agent) ConnStateHandler ¶
ConnStateHandler is used to monitor the state of NATS connection. This method should be called when NATS connection state changes: connect, disconnect, close. Not calling this method after connection state change will result in other agents losing the knowledge about services registered by this instance of Agent.
func (*Agent) Discover ¶
func (a *Agent) Discover(serviceName string, includeLocal bool) []*ServiceInfo
Discover returns a list of last known addresses of a service. If includeLocal is false, the services registered by this instance of Agent using Register() will be omitted.
func (*Agent) Register ¶
func (a *Agent) Register(info *ServiceInfo) error
Register registers a service instance making it available for discovery by other services.
func (*Agent) Stop ¶
Stop stops the discovery service. It will notify other instances that all services registered by this agent instance are no longer available. The agent will forget all known remote services immediately. Local services list is kept intact.
func (*Agent) Unregister ¶
func (a *Agent) Unregister(info *ServiceInfo) error
Unregister removes a service instance making it unavailable for discovery by other services.