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 PubSubBridge data to GCP PubSub - 图1 (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

  1. Create a Service AccountBridge data to GCP PubSub - 图2 (opens new window) in your GCP account. Ensure that the Service Account has permissions to at least publish messages to the topic of interest.
  2. Create a Service Account Key for that account and download it in JSON format.
  3. Create a PubSub topic (remember that the Service Account must have permissions to publish to that topic).

Create the PubSub resource

Go to EMQX DashboardBridge data to GCP PubSub - 图3 (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”.

Creating a GCP PubSub resource

Create the Rule and Action

Go to EMQX DashboardBridge data to GCP PubSub - 图5 (opens new window), select the “Rule Engine” item on the menu to the left, then “Rule”. Then, click “Create”.

Type in the following SQL:

  1. SELECT
  2. *
  3. FROM
  4. "t/gcp"

Creating a rule to forward data to GCP PubSub

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”.

Binding an action to forward data to GCP PubSub

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:

  1. Topic: "t/gcp"
  2. QoS: 0
  3. Retained: false
  4. Payload: "hello"

You may check that the metrics have increase for that rule with the successful publishing.

GCP PubSub metrics

By pulling the messages from the PubSub topic, you can verify that the data has been forwarded to GCP.

  1. # Create a subscription to your topic
  2. gcloud pubsub subscriptions create my_subscription_id --topic=mytopic
  3. # Pull data
  4. gcloud pubsub subscriptions pull my_subscription_id --auto-ack