Skip to content

How to Create a 4.1.2 Service Provider

Kadosa Koltai edited this page Oct 17, 2019 · 4 revisions

The work of a provider is slightly more complex:

  1. Register its service
  2. Wait for a consumer
  3. Serve the consumer

Registering a Service

In the Arrowhead Framework the Core System to target is the Service Registry. In the Arrowhead Framework communication with the Core services is done through HTTP messages.

Finding the URL of the Service Registry

As currently Arrowhead doesn't really support discovery, it has to be statically available.

It'll either end up hardcoded, or, better, in the config file. Arrowhead provides some utilities for reading config files.

The Service Registry expects a Service Registry Entry.

Crafting the Service Registry Entry

Firstly, the system needs to identify itself, which is done by creating an Arrowhead System type object of itself. This basically requires a name, by which IP address and port number the system can be reached, and a null for security info.

Then the kind of provided service needs to be defined, which is done by creating an Arrowhead Service type object.

  • The serviceDefinition is the name of the provided service. Only consumer searching for this exactly will be using this service.
  • The set of interfaces define what interfaces this system supports on the above declared address:port for this service. The Arrowhead framework currently does not define protocols to match interface names.
  • The metadata can contain miscellaneous information about the service, in key-value pairs. Be advised, that currently the whole metadata is stored in a varchar(255).

Registering

Is done by sending a REST POST to the Service Registry. The path in the URI is serviceregistry/register. To be sure about the URI, use the Utility.getUri function. (This means the Orchestrator's URL should be stored in an are-we-safe, IP adress, port number triplet.)

For sending the http message, use the Utility.sendRequest, to receive an Arrowhead Exception in case of a problem.

Serving

Once the registration completes, the system may get request to its port, as defined by the interfaces it promised to implement. This process is largely independent of the Arrowhead Framework.

Notably, because the Arrowhead Framework associates both the IP address and port number to the system, if the system would like to provide multiple services, they will still come in at the same port. For this reason, the use of REST is advised in this case.

End of Life

When a service ends, it should send an unregister request to the Service Registry.

This message should contain the Service Registry Entry of the service, and should be sent as a http PUT request, should be sent at the Service Registry's URL with the path of serviceregistry/remove.

Trying to register a service already in the registry will throw an Arrowhead Exception. Because of this, using a try-cach block and checking the Exception Type might be useful.