The HelperForLocalMicroServices is a helper service used to register and deregister local microservices. Why do you need a helper to do this? The problem is the asynchronous nature of a nyssr.net kernel. It may well be that at the time your microservice is initialized, no microservice registry is known. The registry will broadcast when your node boots up. We could of course subscribe to this broadcast and only send a message to register when the registry appears. However, it is easier to use this special service for this purpose. The service takes the registration data, waits for the registry and then registers your service.
Getting the service
The service is available through the local service registry.
final IHelperForLocalMicroServices helper = CServiceRegistry.getInstance() .getService(IHelperForLocalMicroServices.class);
As always, make sure that the service starter of your package has a dependency on the helper service to ensure that the service already exists.
Add a microservice
There are two types of registration. The first method uses individual data for registration, while the second uses a helper class.
boolean registerMicroService(@NotNull IId aMicroServiceId, @NotNull String aDescription, @NotNull Collection<CDescriptionOfRecord> aNanoServices, @NotNull IId aInstanceId, @NotNull CTargetAddress aInstanceAddress) throws CException; boolean registerMicroService(@NotNull CMicroServiceInstance aInstance) throws CException;
The Microservice ID, a description, an Instance ID (freely selectable), the Microservice Target Address and a description of the API are required for registration.
Remove a microservice
The first method removes a microservice using the target address. All microservices of the target are removed (there can be more than one).
void deregisterMicroServices(@NotNull CTargetAddress aRequester) throws CException;
The other method removes a single microservice instance.
void deregisterMicroService(@NotNull IId aMicroServiceId, @NotNull IId aInstanceId) throws CException;