Bridge data to GCP PubSub
Starting from EMQX Enterprise e4.4.11, EMQX’s Rule-Engine supports Google GCP PubSub integration.
EMQX GCP PubSub integration can send MQTT messages and events to Google Cloud PubSub (opens new window), which can help you flexibly choose services on Google Cloud and build IoT applications more easily.
The following steps will guide you to use this configuration.
TIP
Introduced in e4.4.11
Setup
- Create a Service Account (opens new window) in your GCP account. Ensure that the Service Account has permissions to at least publish messages to the topic of interest.
- Create a Service Account Key for that account and download it in JSON format.
- Create a PubSub topic (remember that the Service Account must have permissions to publish to that topic).
Create the PubSub resource
Go to EMQX Dashboard (opens new window), select the “Rule Engine” item on the menu to the left, then “Resources”. Then, click “Create”.
In the dialog, select the GCP PubSub type, and click “Select file” to choose and upload the Service Account JSON file for the Service Account you are going to use. Click “Confirm”.
Create the Rule and Action
Go to EMQX Dashboard (opens new window), select the “Rule Engine” item on the menu to the left, then “Rule”. Then, click “Create”.
Type in the following SQL:
SELECT
*
FROM
"t/gcp"
Then, click on “Add Action”. Select the Action Type “Data Forward”, “Data to GCP PubSub” and in “Use of resources” select the GCP PubSub resource previously created. Fill in the parameters for the action. The only required parameter to define here is the PubSub Topic where the messages should be forwarded to. Click “Confirm”.
Finally, click “Create” at the bottom of the page.
Test the Action
You can test the new Action by sending a MQTT message to EMQX:
Topic: "t/gcp"
QoS: 0
Retained: false
Payload: "hello"
You may check that the metrics have increase for that rule with the successful publishing.
By pulling the messages from the PubSub topic, you can verify that the data has been forwarded to GCP.
# Create a subscription to your topic
gcloud pubsub subscriptions create my_subscription_id --topic=mytopic
# Pull data
gcloud pubsub subscriptions pull my_subscription_id --auto-ack