# Hot Path Subscription Example

The ABB Ability™ Platform provides a way to read alarms, events, platform events, and telemetry/variable data from the Platform in real time using the "Hot" path endpoint. This provides a faster, more performative way to request live data from the ABB Ability™ Platform, compared to the "Warm" or "Cold" path routes.

Inside the platform instance, device telemetry and platform events are routed through an Azure Service Bus Namespace via their respective service bus topics, which can be subscribed to for access to live data. This application uses the Subscriptions endpoint in the Data Access API to perform CRUD operations on a hot path subscription. A subscription can be created, renewed, and deleted via this endpoint.

We have created a .NET and Node.js examples of how to use Hot Path subscription functionality of Ability Platform.

In this tutorial, the applications function as follows:

  1. The application reads a configuration file containing the Instance API endpoint URL, the type of subscription to create, the components of the subscription request body, etc.

  2. The application uses information from the JSON response to the subscription request to create a service bus subscription client to receive messages on the Azure Service Bus topic.

  3. The app listens for hot path data and writes this data to the console output.

  4. The application runs for the life of the subscription request. When it completes, the application closes the client and deletes the subscription if it has not already expired.

# Prerequisites

Follow the article with the technology of your liking.

    To make a call to the API management gateway for the subscription endpoint, the application will need to present a bearer token as the value of the Authorization header in the POST request. Information about authorization with Ability APIs can be found here.

    In this example we're using the Background Application (OAuth 2.0 Client Credentials flow). Have a look at how the access token is fetched:

      You can also use another authorization flow, but in such case you need to provide the access token by yourself (more on that later).

      # Create the Hot Path Subscription

      # Example Configuration Files

        The apps are able to read the token from the configuration file, or they can fetch it using a Background Application identity. If you decide to provide access token in the configuration, don't bother with settings of:

        • access token URL
        • client ID
        • client secret
        • B2C Tenant
        • solution namespace

        They will not be used.

        Ability Sandbox

        If you are an Ability Sandbox user, you have to provide a pre-generated access token. Sandbox users are not able to create Background Applications.

        # Example Subscription Filter

        // Will filter for all data associated with specific variable of specified objectId
        "objectId='<some object id>' AND variable='<some variable name>'"
        

        # Hot Path Subscription Response

        After performing a POST to the Subscriptions/{type} endpoint, the application will parse the JSON response for data needed to create a subscription client object.

        # Response Body

        {
        "subscriptionId": "<Subscription ID GUID>", // Name of application created subscription
        "sasToken": "<Example SAS Token>", // Used to authenticate against the Service Bus Namespace
        "connectionUrl": "<URL>" // Will be parsed for fully qualified namespace and entity path of client object
        }
        

        # Listen for Hot Path Data

          # Renew or Delete a Subscription

          When the Service Bus SAS token and Service Bus Topic Subscription expire, the application will terminate. Before ending, the application will close the client and delete the subscription using the DELETE message request, based on the /{{type}/{subscriptionId} of the subscription.

          The lifetime of the SAS token can be extended, using the PUT message request based on the /{{type}/{subscriptionId} of the subscription. The provided samples do not cover that.

          WARNING

          If the bearer token expires before the subscription delete is called, the DELETE will fail with 403 Forbidden error

          # Running the Application

            # Validate The Application is Listening for Data

            WARNING

            By default, if no filtering is provided to the client, the application will listen to all messages on the specified Service Bus topic of the subscription for the entire platform instance.

            In a running platform instance, there should be a number of steady telemetry streams comprising of data from connected edge devices, running applications, platform events, etc. These streams can be subscribed to and used to validate the functionality of the Hot Path Subscription application. The application can be validated by using a variety of methods. Some examples are given below:

            • An ABB Ability™ Edge on the platform instance, sending heartbeat telemetry to the Platform

            • An ABB Ability™ Edge running a custom module sending telemetry data or alarms and events.

            • An application using the publishers data reingestion endpoint

            • A curl command simulating data being pushed into the platform, using the Publishers Reingestion Endpoint

            1. Create Publisher Token
              curl -X POST \
              https://api-xxxxx.abilityplatform.abb/v1/publishers/<application id>/token \
              -H 'Authorization: Bearer  <token>' \
              -H 'Content-Type: application/json' \
              -H 'cache-control: no-cache' \
              -d '{
                  "sasTokenTTL": 60
              }'
            
            1. Publish Data using SaS Token and Connection Url provided by token request
              curl -X POST \
              <Connection Url> \
              -H 'Authorization: <SaS Token>' \
              -H 'Content-Type: application/json' \
              -H 'ability-messagetype: <Type of Data to Push, usually <'timeSeries'>' \
              -H 'cache-control: no-cache' \
              -d '[
                  {
                    "model": "<Model of Information Model Object associated with Data>",
                    "value": "<Value to be pushed>",
                    "objectId": "<Object Id of Information Model Object instance>",
                    "timestamp": "<Timestamp using ISO 8601 Round-trip Format Specifier>",
                    "variable": "<Variable Name>"
                  }
              ]'
            
            Last updated: 2/3/2022, 12:56:12 PM
            Feedback