# Bridge device data to MQTT Broker Using the Data Integrations

In order to facilitate the message bridging of multiple MQTT Brokers, you can use the Data Integrations to operate.

This guide will create a a data integration bridged by MQTT Broker to achieve the following functions:

  • Forward all messages sent to the greet topic to another MQTT Broker

In order to achieve this function, we will complete the following 4 tasks:

  1. Start Mosquitto service
  2. Set the filter conditions of the data integration
  3. Create a resource and an action
  4. Complete the data integrations creation and test

Tip

Before using the Data Integrations, create a deployment first. For professional deployment users: please complete Peering Connection first, and ensure that the servers involved in the following are established in the VPC under the peering connection. All the IP mentioned below refer to the intranet IP of the resource For basic deployment users: There is no need to complete peering connection, and the IP mentioned below refers to the public IP of the resource

# Create Mosquitto service

In your cloud server, create a mosquitto service. For the convenience of demonstration, we use docker to build quickly here. (Do not use it in production environment)

docker run -it -p 1883:1883 --name mosquitto eclipse-mosquitto:1.6
1

After that, open the server's 1883 port

# EMQX Cloud Data Integrations configuration

Enter EMQX Cloud Console (opens new window), and click to enter the deployment to use MQTT Broker bridge.

On the deployment page, drop down to select the MQTT Bridge resource type.

data_integration

# Create resources and actions

  1. New Resource

    Click on Data Integrations on the left menu bar,fill in the private address of the server in the remote broker address, place the mount point on emqx/, and click Test. If "test available" returns, it means the test was successful.

    Tip

    If the test fails, please check whether the VPC peering connection is completed and whether the IP address is correct.

    create resource

  2. Rule Testing

    Our goal is to trigger the engine when the topic of greet receives messages. Certain SQL processing is required here:

  • Only target 'greet/#'

    According to the above principles, the SQL we finally get should be as follows:

    SELECT
      payload.msg as msg
    FROM
      "greet/#"
    
    1
    2
    3
    4

    add_rule add_rule

  1. Add a response action

    Click Next, select the resource created in the first step, and fill in "${msg} FROM EMQX CLOUD" in the message content template, and click confirm: add_action

# Test

If you are using EMQX Cloud for the first time, you can go to Deployment Connection Guide to view the MQTT client connection and test guide

When configuring the action in the third step, we set the mount point to emqx/. Therefore, we use the client to subscribe to the topic emqx/# of Mosquitto.

At the same time, we send "hello" to the greet topic of EMQX Cloud, and the rule engine will be triggered. We can see that Mosquitto has received the message of "hello FROM EMQX CLOUD"

messages