MOD12: OI4 Service Registry Listener - GoranErdeljan/TINF19C-Team-4-Service-Registry GitHub Wiki

Created by Benedict Wetzel

1. Introduction

This module handles new services on the OI4-MessageBus, listens to mDNS-Queries used by the DNS-SD mechanism and sends a response to these queries for every service it knows, with the Master-Asset-Model as TXT-Records.

2. Requirements

The following requirements are covered by this module:

3. Prerequisites

In order to use this module the following prerequisites should be met:

  • The developer should have a working computer that can access the internet
  • The developer should use a Linux-based OS
  • The developer should have Node.js version 12.14.1 or higher installed
  • The developer should have NPM version 7.10.0 or higher installed
  • The developer should have at least some basic experience with Node.js

4. Dependencies

This module depends on the following items:

5. Technical overview

This module subscribes to topic at the MQTT-Broker, where according to the specification by the OI4 all Master-Asste-Models are published. For this module you must the validator, for example to MOD13, as it is done in the main.js of MOD10.

5.1 oi4Listener.js

The oi4Listener.js holds all logic of the module. This file depends on the NPM packages mqttjs and multicast-dns.

Function Description
setConfig Sets the configuration of the module
start This function starts the module. It connects to the MQTT-Broker and subscribes to the Topic "oi4/+/+/+/+/+/pub/mam/#" to find all new devices on the OI4-MessageBus. It also registers a handler function for any mDNS-queries, that responds to those with a mDNS-response for each service it knows. The configuration must be set before the start function is called
monitorHealthOfDevices This function is called once with the start-function to create a MQTT-Client that listens to all Health-messages. Since all devices are required by the OI4 specification to send a Health-message at least every 60 seconds, the application uses this information to determine whether a service is alive. If a service does not send a health-message within a 60-second interval, it is removed from the list of active services and is no longer announced via DNS-SD. If a Health-message is received from a device that does not appear in the list of active services, it will be requested to publish its Master-Asset-Model so that it can be discovered and also added to the list of active services. This method of discovering services should result in a maximum delay between a service coming online and the discovery of 60 seconds
buildTXTOfMAM This function builds TXT records based on a Master-Asset-Model. It adds oi4=true as a record, because this information is used to distinguish devices that communicate over the MQTT-Broker from other devices on the network. It also adds a record for the DataSetWriterId, so that the application knows that these records were written by the application itself and therefore don't need to be added to the OI4-Message-Bus.

5.2 package.json

Sets the dependencies and is used by NPM to install the required NPM packages.