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

Kafka Integration

10min

To configure the Kafka integration, complete the following steps.

Step 1: Add Device



Step 2: Add Tags



Step 3: Add Kafka 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 the Kafka SSL provider from the drop-down menu. In this guide, we are using Confluent Kafka as the Kafka broker, so we selected Kafka SSL Integration.
  4. Complete the following information for the Kafka SSL connector as shown in the screenshot and click Add/Update.

    Edit a connector
    Edit a connector
    
  5. Click the kafka SSL 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 Kafka Connector
    Topics tab in Kafka Connector
    

Step 4: Set Up Databricks for Kafka Streaming

In Databricks, you can configure Kafka connector parameters from a Python notebook file. You will need to input information about the Broker address, Topic name, and API key and secret. To set up Databricks for Kafka streaming:

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

2. Create a new notebook in Databricks. Follow the Databricks Kafka Streaming Guide to set up Kafka 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 value field in binary format.

Example Notebook for Kafka 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 Kafka data streams and process data using PySpark. 

Python


2. Define the credentials and Kafka broker information that will be used to authenticate and connect to the Kafka server.

Note: End-users should use secure methods of passing their Kafka credentials.

Python


3. Configure Spark to read data streams from the Kafka topic.

Note: Ensure to include the Kafka server, security protocol, and authentication details.

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 Kafka stream data accordingly.

Python


This will output the following:

Dataframe format
Dataframe format


5. Specify the Databricks table where the parsed data will be stored.

Python


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