registry

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 18 Imported by: 0

README

Dynamic Service Discovery

Nucleo framework has a built-in service responsible for node/service discovery and periodic heartbeat verification. The discovery is dynamic meaning that a node does not need to know anything about other nodes on startup. When a node/service/actions starts, it will announce it’s presence to the service discovery and that will be saved in the registry. In case of a node crash (or stop) other nodes will detect it and remove the affected services from their registry. This way the following requests will be routed to live nodes or users will be signaled.

Service Registry

Nucleo has a built-in service registry module. It stores all information about services, actions, event listeners and nodes. When you call a service or emit an event, broker asks the registry to look up a node which executes the request. If there are multiple nodes which can serve the request, it uses load-balancing strategy to select the next node.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNode

func CreateNode(id string, local bool, logger *log.Entry) nucleo.Node

Types

type ActionCatalog

type ActionCatalog struct {
	// contains filtered or unexported fields
}

func CreateActionCatalog

func CreateActionCatalog(logger *log.Entry) *ActionCatalog

func (*ActionCatalog) Add

func (actionCatalog *ActionCatalog) Add(action service.Action, serv *service.Service, local bool)

Add a new action to the catalog.

func (*ActionCatalog) Find

func (actionCatalog *ActionCatalog) Find(name string) []ActionEntry

func (*ActionCatalog) Next

func (actionCatalog *ActionCatalog) Next(actionName string, stg strategy.Strategy) *ActionEntry

Next find all actions registered in this node and use the strategy to select and return the best one to be called.

func (*ActionCatalog) NextFromNode

func (actionCatalog *ActionCatalog) NextFromNode(actionName string, nodeID string) *ActionEntry

func (*ActionCatalog) Remove

func (actionCatalog *ActionCatalog) Remove(nodeID string, name string)

func (*ActionCatalog) RemoveByNode

func (actionCatalog *ActionCatalog) RemoveByNode(nodeID string)

RemoveByNode remove actions for the given nodeID.

func (*ActionCatalog) Update

func (actionCatalog *ActionCatalog) Update(nodeID string, fullname string, updates map[string]interface{})

type ActionEntry

type ActionEntry struct {
	// contains filtered or unexported fields
}

func (ActionEntry) IsLocal

func (actionEntry ActionEntry) IsLocal() bool

func (ActionEntry) Service

func (actionEntry ActionEntry) Service() *service.Service

func (ActionEntry) TargetNodeID

func (actionEntry ActionEntry) TargetNodeID() string

type ActionError

type ActionError struct {
	// contains filtered or unexported fields
}

func (*ActionError) Action

func (e *ActionError) Action() string

func (*ActionError) Error

func (e *ActionError) Error() string

func (*ActionError) Stack

func (e *ActionError) Stack() string

type EventCatalog

type EventCatalog struct {
	// contains filtered or unexported fields
}

func CreateEventCatalog

func CreateEventCatalog(logger *log.Entry) *EventCatalog

func (*EventCatalog) Add

func (eventCatalog *EventCatalog) Add(event service.Event, service *service.Service, local bool)

Add a new event to the catalog.

func (*EventCatalog) Find

func (eventCatalog *EventCatalog) Find(name string, groups []string, preferLocal bool, localOnly bool, stg strategy.Strategy) []*EventEntry

Find find all events registered in this node and use the strategy to select and return the best one to be called.

func (*EventCatalog) Remove

func (eventCatalog *EventCatalog) Remove(nodeID string, name string)

func (*EventCatalog) RemoveByNode

func (eventCatalog *EventCatalog) RemoveByNode(nodeID string)

RemoveByNode remove events for the given nodeID.

func (*EventCatalog) Update

func (eventCatalog *EventCatalog) Update(nodeID string, name string, updates map[string]interface{})

type EventEntry

type EventEntry struct {
	// contains filtered or unexported fields
}

func (*EventEntry) IsLocal

func (eventEntry *EventEntry) IsLocal() bool

func (*EventEntry) String

func (eventEntry *EventEntry) String() string

func (EventEntry) TargetNodeID

func (eventEntry EventEntry) TargetNodeID() string

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) Available

func (node *Node) Available()

Unavailable mark the node as available

func (*Node) ExportAsMap

func (node *Node) ExportAsMap() map[string]interface{}

ExportAsMap export the node info as a map this map is used to publish the node info to other nodes.

func (*Node) GetID

func (node *Node) GetID() string

func (*Node) HeartBeat

func (node *Node) HeartBeat(heartbeat map[string]interface{})

func (*Node) IncreaseSequence

func (node *Node) IncreaseSequence()

func (*Node) IsAvailable

func (node *Node) IsAvailable() bool

func (*Node) IsExpired

func (node *Node) IsExpired(timeout time.Duration) bool

func (*Node) IsLocal

func (node *Node) IsLocal() bool

func (*Node) Publish

func (node *Node) Publish(service map[string]interface{})

func (*Node) Unavailable

func (node *Node) Unavailable()

Unavailable mark the node as unavailable

func (*Node) Update

func (node *Node) Update(id string, info map[string]interface{}) bool

type NodeCatalog

type NodeCatalog struct {
	// contains filtered or unexported fields
}

NodeCatalog catalog of nodes

func CreateNodesCatalog

func CreateNodesCatalog(logger *log.Entry) *NodeCatalog

CreateNodesCatalog create a node catalog

func (*NodeCatalog) Add

func (catalog *NodeCatalog) Add(node nucleo.Node)

func (*NodeCatalog) HeartBeat

func (catalog *NodeCatalog) HeartBeat(heartbeat map[string]interface{}) bool

HeartBeat delegate the heart beat to the node in question payload.sender

func (*NodeCatalog) Info

func (catalog *NodeCatalog) Info(info map[string]interface{}) (bool, bool)

type ServiceCatalog

type ServiceCatalog struct {
	// contains filtered or unexported fields
}

func CreateServiceCatalog

func CreateServiceCatalog(logger *log.Entry) *ServiceCatalog

func (*ServiceCatalog) Add

func (serviceCatalog *ServiceCatalog) Add(service *service.Service)

Add : add a service to the catalog.

func (*ServiceCatalog) Find

func (serviceCatalog *ServiceCatalog) Find(name string, version string, nodeID string) bool

Has : Checks if a service for the given name, version and nodeID already exists in the catalog.

func (*ServiceCatalog) FindByName

func (serviceCatalog *ServiceCatalog) FindByName(name string) bool

func (*ServiceCatalog) Get

func (serviceCatalog *ServiceCatalog) Get(name string, version string, nodeID string) *service.Service

Get : Return the service for the given name, version and nodeID if it exists in the catalog.

func (*ServiceCatalog) RemoveByNode

func (serviceCatalog *ServiceCatalog) RemoveByNode(nodeID string) []*service.Service

RemoveByNode remove services for the given nodeID.

type ServiceEntry

type ServiceEntry struct {
	// contains filtered or unexported fields
}

type ServiceRegistry

type ServiceRegistry struct {
	// contains filtered or unexported fields
}

func CreateRegistry

func CreateRegistry(nodeID string, broker *nucleo.BrokerDelegates) *ServiceRegistry

func (*ServiceRegistry) AddLocalService

func (registry *ServiceRegistry) AddLocalService(service *service.Service)

AddLocalService : add a local service to the registry it will create endpoints for all service actions.

func (*ServiceRegistry) BroadcastEvent

func (registry *ServiceRegistry) BroadcastEvent(context nucleo.BrokerContext) []*EventEntry

func (*ServiceRegistry) HandleRemoteEvent

func (registry *ServiceRegistry) HandleRemoteEvent(context nucleo.BrokerContext)

HandleRemoteEvent handle when a remote event is delivered and call all the local handlers.

func (*ServiceRegistry) KnowAction

func (registry *ServiceRegistry) KnowAction(name string) bool

func (*ServiceRegistry) KnowNode

func (registry *ServiceRegistry) KnowNode(nodeID string) bool

func (*ServiceRegistry) KnowService

func (registry *ServiceRegistry) KnowService(name string) bool

func (*ServiceRegistry) KnownEventListeners

func (registry *ServiceRegistry) KnownEventListeners(addNode bool) []string

func (*ServiceRegistry) KnownNodes

func (registry *ServiceRegistry) KnownNodes() []string

func (*ServiceRegistry) LoadBalanceCall

func (registry *ServiceRegistry) LoadBalanceCall(context nucleo.BrokerContext, opts ...nucleo.Options) chan nucleo.Payload

DelegateCall : invoke a service action and return a channel which will eventualy deliver the results ;). This call might be local or remote.

func (*ServiceRegistry) LoadBalanceEvent

func (registry *ServiceRegistry) LoadBalanceEvent(context nucleo.BrokerContext) []*EventEntry

LoadBalanceEvent load balance an event based on the known targetNodes.

func (*ServiceRegistry) LocalNode

func (registry *ServiceRegistry) LocalNode() nucleo.Node

func (*ServiceRegistry) LocalServices

func (registry *ServiceRegistry) LocalServices() []*service.Service

func (*ServiceRegistry) ServiceForAction

func (registry *ServiceRegistry) ServiceForAction(name string) []*service.Service

func (*ServiceRegistry) Start

func (registry *ServiceRegistry) Start()

Start : start the registry background processes.

func (*ServiceRegistry) Stop

func (registry *ServiceRegistry) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL