How-To Guides
...
Databricks Integration
Streaming with Kafka & GCP Pub...

GCP Pub/Sub Integration

8min

To configure the GCP Pub/Sub integration, complete the following steps.

Step 1: Add Device

Follow the steps to Connect a Device. The device will be used to store tags that will be eventually used to create outbound topics in the connector. Make sure to select the Enable Data Store checkbox.

Step 2: Add Tags

After connecting the device in Litmus Edge, you can Add Tags to the device. Create tags that you want to use to create outbound topics for the connector.

Step 3: Add Google Cloud Pub/Sub Connector

To add the Kafka connector in Litmus Edge:

  1. Navigate to Integration.
  2. Click Add a connector icon. The Add a connector dialog box appears.
  3. Select Google Cloud Pub/Sub provider from the drop-down list.
  4. Complete the following information for the Google Cloud Pub/Sub connector as shown in the screenshot and click Update.

    Edit a connector dialog box
    Edit a connector dialog box
    
  5. Click the Google Cloud Pub/Sub connector tile. The connector Dashboard appears.
  6. Click the Topics tab.
  7. Click the Import from DeviceHub tags icon and select all the tags to send data to Databricks.

    Topics tab in Google Cloud Pub/Sub connector
    Topics tab in Google Cloud Pub/Sub connector
    

Step 4: Set Up Databricks for GCP Pub/Sub Streaming

In Databricks, you can configure GCP Pub/Sub connector parameters from a Python notebook file. You need to authenticate using service account credentials and specify Pub/Sub topic.

To set up Databricks for GCP Pub/Sub Streaming:

1. Navigate to Databricks workspace using your log in credentials.

2. Create a new notebook in Databricks. Follow the Databricks Pub/Sub Streaming Guide to set up Google Pub/Sub streaming.

3. Once the data is loaded, it will be in the following format:

Dataframe format
Dataframe format


The payload sent by LE will be in the payload field in binary format.

Example Notebook for GCP Pub/Sub Streams

Note: The user can create their own notebooks and customize them as needed. This example notebook will explain how to ingest the standard DeviceHub JSON Payload.

Open a new notebook and follow the steps:

1. Import the necessary libraries and dependencies to handle Pub/Sub data streams and process data using PySpark.

Python


2. Define the credentials and GCP Pub/Sub information that will be used to authenticate and connect to the Pub/Sub service.

Note: End-users should use secure methods of passing their Pub/Sub credentials.

Python


3. Configure Spark to read data streams from the Pub/Sub topic.

Note: Ensure to include the subscription ID, topic ID, project ID, and authentication options.

Python


This will output the following:

Dataframe format
Dataframe format


Note: This guide covers the DeviceHub JSON Payload. Please update the notebook if you are sending a different payload to Databricks.

4. Define the schema that matches the expected structure of the incoming data and parse the Pub/Sub stream data accordingly. This involves decoding the payload, extracting attributes, and structuring the parsed data into a DataFrame.

Python


5. Once the data is published to the Databricks table, you can query the table to verify that the data ingestion process is successful.

Databricks table
Databricks table