Write to the Database with Integration Topics

Estimated reading time: 1 minute

Flows can easily send data to the database through Integration topics.


Add a Database Integration Topic

  1. Click to enable a database Integration.

  2. Click on a database Integration that has Online status.
  3. Click to add a new topic.
  4. Enter a name for the topic. Check Enable.

  5. Click OK to start using this topic to send data to the database.

Create the Flow

  1. Open Flows. Add a new flow.
  2. To write to the Database: Connect an Inject node, a Function node, and a Datahub Publish node.
  3. To read from the topic: Connect a Datahub Subscribe node, and a Debug node.

  4. Double-click the Function node. Enter the following lines of code. Make sure to change some sections to match your topic and database:

    var obj = {}; // Create an empty JSON object.
    obj.name ="mysqltopic"; // Write the name of your database integration topic in the quotation marks.
    obj.num = 99000; // Change num to be one of the names of your columns. Change 99000 to a value that you want to insert into the database.
    msg.payload = JSON.stringify(obj); // Puts the JSON object into the message payload.
    msg.subjectInput = "mysqltopic"; // Write the name of your database integration topic in the quotation marks.
    return msg;
  5. Double-click the Datahub Publish node. Select your Datahub from the drop-down menu. Click Done.

  6. Double-click the Datahub Subscribe node. Select your Datahub and enter the name of your Integration topic. Click Done.

  7. Save the flow. Click the Inject node button to insert rows into the Database. The debug window will show the inserted JSON objects.

    Query the database to confirm that the Integration topic inserted the data properly.