Event emitted when a service becomes available.
subscribable
Event emitted when a service becomes unavailable.
subscribable
Event emitted when a service is updated.
subscribable
Get information about a service with the given identifier.
Service
instance or null
if service is unavailable
Join the services layer allowing access to remote services.
promise that resolves when services have started
Leave the services no longer allowing access to remote services.
promise that resolves when services have stopped
Register an object using a specific identifier.
handle that can be used to remove service
Register an object that contains a service identifier.
handle that can be used to remove service
Generated using TypeDoc
Distributed service registry for exposing and consuming remote services.
Service contracts
The service support is built around contracts that define what methods and events are supported. Contracts are defined using ServiceContract:
Implementing and registering services
When a contract has been defined it should be implemented, either as a class or as a one-off instance.
Classes
Classes are commonly implemented using a decorator to indicate what contract they support:
Instance
Instance implementations are useful for singleton services without events:
Consuming services
Services are commonly consumed either by their identifier or dynamically using events.
Events
It is possible to listen for events becoming available and unavailable using onServiceAvailable and onServiceUnavailable:
Updates to services can occur if multiple instances are registered for the same id, in which case they are merged and update events emitted if the supported methods and events change:
Getting specific services
get can be used to get a service based on a known identifier. Doing so allows you to determine its availability, listen to changes, events and invoke methods.
Events are available on the service instance and can be used to listen for changes to it, see Service.onAvailable, Service.onUnavailable and Service.onUpdate.
Creating proxies
Creating a proxy is the recommended way to call methods and listen to events from a service. It allows for a very similar style of use for services that are remote as for services that are local.
Proxies are created from a contract and use the methods and events defined in them to create the proxied instance:
A proxied service can then be called as a normal class:
Events work similar to how they would locally:
Methods in a contract will become a method on the proxy that returns a
Promise
, so method calls must always be awaited to retrieve the result. Events will become an instance of AsyncSubscribable.