Page tree
Skip to end of metadata
Go to start of metadata

LinksmartGateway Configuration

This is a Nifi processor which functions similar to the Linksmart Gateway. A user can specify a sub-process to run under this processor. This processor will catch the stdout of that sub-process and propagate the information into the Nifi system. This processor has the following properties:

Property NameDescription
Command LineThe command line to be executed in a subprocess.
Maximum Message Queue SizeThe maximum number of messages to add to a single FlowFile. If multiple messages are available, they will be concatenated along with the up to this configured maximum number of messages.
Maximum Batch SizeThe maximum number of messages to add to a single FlowFile. If multiple messages are available, they will be concatenated along with the up to this configured maximum number of messages.
Batching Message DelimiterSpecifies the delimiter to place between messages when multiple messages are bundled together (see property).

Example for Sub-process

In principle, as long as a sub-process writes data to its stdout channel, it could be used with the LinkSmartGateway. Typically, a user can specify a script, e.g. a Python script, to be run as a sub-process. In that script, some sensor data will be read and published to the stdout channel. In practice, the sub-process should follow the following principles:

  1. The sub-process should be a long running program.
  2. The sub-process should publish useful information to stdout and error messages to stderr, so that the error messages could also be propagated to Nifi interface.
  3. The sub-process should catch the SIGTERM signal, because this is the signal the LinksmartProcessor send to the sub-process, when it tries to terminate it. The sub-process should have a callback function which shuts itself down gracefully (closing opened resources/connections, etc.).
  4. The sub-process should print each outgoing message with a new line symbol at the end (\n or \r\n), as this symbol is used by the processor to separate messages.

As an example, this is a Python script which fits the above principles:

import signal
import sys
import time

# Callback for SIGTERM signal
def sigterm_handler(signal, frame):
    # Release resources and shutdown program
    # ...
    sys.exit(0)
    
# Catch SIGTERM signal
signal.signal(signal.SIGTERM, sigterm_handler)

# A long running loop which keeps publishing data to stdout
while True:
    # Do your stuff
    print('new data') # A new line symbol is implicitly included
    sys.stdout.flush() # Since Python caches its stdout, you need to flush it explicitly 
    time.sleep(1)

Let's assume the above script is saved as/scripts/dummy.py in the same host as the running Nifi instance. Then in the Command Line property of the LinksmartProcessor, you can fill in python /scripts/dummy.py. Run the processor, and the message will be published by the LinksmartProcessor.

LinksmartServiceRegister Configuration

This processor is responsible for registering a service entry to the Linksmart Service Catalog. It has the following parameters:

Property NameDescription
Service Catalog URLThe URL of the Linksmart Service Catalog.
Service IDThe ID of this service, which will be used for identification in the Linksmart Service Catalog. If left empty, a random UUID will be assigned automatically by the Service Catalog
Service Entry BodyThe content to be sent to the Service Catalog

Once scheduled, this processor will take care of registering a service entry in the Linksmart Service Catalog. Once it is stopped, it will delete the service entry in the catalog. Once scheduled, this processor will take care of registering a service entry in the Linksmart Service Catalog. Once it is stopped, it will delete the service entry in the catalog.

  • No labels