Example: Create a Data Source and a Stream Application

This section will show how to develop a Stream Application. This example will walk you through the process of subscribing to an MQTT topic to receive data from a Thing and storing the data received in an external PostgreSQL database.
  1. Open the Data Sources menu under Stream Processing.
    Figure 1.


  2. To set this Data source to be only visible to you and to no one else, select the folder My Workspace.
  3. Select + New Data Source.


  4. Enter a name for the new data source and click Create.
  5. Select the Connector drop-down.
  6. Select MQTT in the Input section of the drop-down list.
    Figure 2.


  7. Update the broker URL to be tcp://mqtt.swx.altairone.com:1883
    Figure 3.


  8. Populate the Topic field with the MQTT topic of the AnythingDB Thing from which you want to process data. This should be in the format spaces/<space>/things/<thing_id>/properties-history/+
  9. Populate the User Id and password. These can be found on the Interfaces tab of the Details page of the Thing you are trying to connect to. Detailed information can be found here
  10. Select Generate Columns.
    Note: Your device must be sending Data to generate columns. If Stream Processing does not detect any messages within the limit, it will timeout.
  11. Select Save.
    The input data sources has been successfully created.
  12. Go back tot he main view and select +New Data Source.
  13. Enter a name for the new data source and click Create.
  14. Select the Connector drop-down.
  15. Select JDBC Legacy in the Output section of the drop-down list.
  16. Enter the following information:
    • Choose URL: This should be in the format jdbc:postgresql://Server/DatabaseName
    • User Id and Password: From your PostgreSQL Database
    • SqlDialect: choose PostgreSQL from the drop-down
    • Table: enter the name of the table defined in your PostgreSQL database
  17. Click the + button to start adding the source parameters (received via MQTT) and the target parameter (defined in your PostgreSQL database).
    Figure 4. Example of an output JDBC Legacy data source


  18. Click Save.
    The output data source has been successfully created.
  19. Move to the Applications tab and click + New Application.
  20. Choose to add an Input operator. From the Data Source drop down menu, choose the MQTT input data source created earlier.
    Figure 5.


  21. Repeat the same process to add an output operator and an input operator, and choose from the data source drop-down from the JDBC output created earlier.
  22. Click Save and Run. Check how the data is being stored in your external PostgreSQL Database.
    Figure 6.