Sava data to MatrixDB

    Access MatrixDB through the command line tool psql and create the table:

    Create a rule:

    Open EMQX Dashboard (opens new window) and select the “Rules” tab on the menu to the left.

    Fill in the rule SQL:

    image-20211201154727219

    Related action:

    Click on the “Add Action” button under “Action Handler”, and then select “Data to MatrixDB” in the pop-up dialog window.

    Fill in the parameters required by the action:

    The following parameters are required by action “Data to MatrixDB”:

    1). Use resource, which is the resource ID. Now the resource drop-down box is empty. You need to create an available MatrixDB resource instance first.

    Click the New button on the right side of Use Resource to enter the Create Resource page. The MatrixDB resource requires the following configurable items:

    Server, the server address of MatrixDB.

    Database, MatrixDB database name.

    User, Password, authentication credentials.

    Eable Reconnect, whether to enable automatic reconnection.

    Pool Size, connection process pool size, which will help obtain the best performance with reasonable configuration.

    Enable SSL, whether to enable TLS connection.

    After the configuration is complete, click OK to complete the creation.

    image-20211201163555899

    After the resource is successfully created, we will return to the Add Action page, and Use Resource is also automatically filled in with the resource ID of the Matrix resource just created.

    3). Max Batch Insert Count, the largest INSERT SQL entry that can be sent in a single batch request.

    4). Max Batch Interval, the maximum waiting interval between two batch requests.

    5). Sync or Async Insert, which determines to make a synchronous or asynchronous call.

    6). Call Timeout. It refers to the timeout for executing actions in synchronous mode. This option is only valid for synchronous insertion.

    7). SQL Template. It contains a placeholder SQL template for inserting or updating data to the database. In this example, we use the following SQL:

    Here we use the placeholder of ${id}, which will be replaced with runtime data when the action is executed.

    image-20211201163937652

    After the configuration is complete, click OK to complete the addition of the action. Then click the Create button at the bottom of the rule page to complete the rule creation.

    After creating MatrixDB resources and rules, we will conduct the test and verification. We directly use the MQTT client tool in Dashboard to publish a message. In this example, we change the message topic to to hit the rules we set. The Payload and QoS remain unchanged. Then, click publish.

    After the message is successfully published, we will be able to see the newly written data in the table: