Developing a CAP Application Integrating MQTT with Integration Suite


This blog post is part of a series of posts describing an integration project which connects the oee.ai Manufacturing Intelligence Platform with the production planning capabilities of an on-premise S/4HANA system. This project was realized by students at FH Aachen – University of Applied Sciences with great support by project partners at oee.ai and SAP. You can check out the main article describing the project here.

In this tutorial video you will learn how to build an SAP CAP application capable of receiving MQTT messages and reacting to them and how to safely deploy it to a Cloud Foundry space on BTP. To accomplish this goal, several SAP technologies such as the BTP CI/CD service and the Credential Store service on BTP are utilized.

During our integration — as described in the main article of this series of blog posts — it was necessary to build such an application. Our use case was that we needed to synchronize production orders marked as finished in our oee.ai system with our S/4HANA system by creating according production order confirmations. A production order is deemed finished as soon as the desired number of produced units defined for the production order is reached.

To accomplish this behavior, our application first connects to the MQTT broker of oee.ai. It then continuously receives messages indicating a finished production order. Once such a message is received, an integration flow is triggered handling the confirmation of the production order in S/4HANA. You can read more about this process here.

Integration%20message%20flow%20%28excerpt%29

We needed to develop this part of the integration ourselves because there currently is no standard way to listen and react to MQTT messages inside SAP Integration Suite. We were required to use Integration Suite though because the information about a finished production order is processed further by an integration flow created in Integration Suite.

Prerequisites

  • Access to SAP BTP. A trial account with the necessary entitlements for the services used works as well.

  • An SAP user account not using SAP Universal ID for authentication

    • Here’s why Universal ID won’t work: We use the BTP CI/CD service to deploy to a Cloud Foundry space. The CI/CD service however does that by programmatically accessing the Cloud Foundry space using the according CLI which requires authentication. But to authenticate via the CLI using SAP Universal ID, a browser seems to be required (scroll down to the last note) which is not practicable in the context of an automated CI/CD job.

    • This account can be different from the account used to set everything up in BTP. Just make sure to assign the necessary role collections to the account to be able to access the Cloud Foundry space to deploy to.

  • An empty Git repository to store the code base of the application, preferably hosted on GitHub or a GitLab instance. Make sure to have it cloned to your local system.

  • Node.js installed, preferably the latest LTS version

  • Any editor or IDE supporting Node.js

Resources

Additional notes

  • To find the endpoint URL provided for your integration flow, open your Integration Suite instance. Select Monitor → Overview → Manage Integration Content and then the integration flow in question.

  • node-fetch and node-jose are required for the boilerplate code used to access the credential store.

  • node-fetch version 3 is not supported because CAP doesn’t seem to support ES modules yet.