Community Edition
ThingsBoard Documentation
Cloud Professional Edition Community Edition IoT Gateway License Server Trendz Analytics
Try it now Pricing
Getting Started Documentation Guides Installation Architecture API FAQ

Kafka Plugin

Important note

Please note that this guide is for ThingsBoard versions prior v2.0.

Old rules and plugins functionality is replaced by new rule engine components (rule chains and rule nodes).

Please review new rule engine documentation to learn how to adopt new functionality.

We are doing our best to modify this guide to v2.0 components. Contributions are welcome.

Overview

Kafka plugin is responsible for sending messages to Kafka brokers triggered by specific rules

Configuration

You can specify following configuration parameters:

  • bootstrap servers - list of kafka brokers
  • number of attempts to reconnect to kafka if connection fails
  • number of messages to unit into batch on client
  • time to buffer locally before sending to kafka broker (in ms)
  • buffer max size on client
  • minimum number of replicas that must acknowledge a write
  • topic key serializer by default - org.apache.kafka.common.serialization.StringSerializer
  • topic value serializer by default - org.apache.kafka.common.serialization.StringSerializer
  • any other additional properties could be provided for kafka broker connection

Server-side API

This plugin does not provide any server-side API.

Example

In this example, we are going to demonstrate how you can configure this extension to be able to send a message to Kafka topic every time new telemetry message for the device arrives.

Prerequisites before contining Kafka extension configuration:

  • Kafka broker is up and running
  • Appropriate Kafka Topic created
  • ThingsBoard is up and running

Kafka Plugin Configuration

Let’s configure Kafka plugin first. Go to Plugins menu and create new plugin:

image

image

Please set correctly Kafka Bootstrap Servers URL and any other parameters located in plugin configuration section that is suitable for your case so Kafka extension is able to connect to Kafka broker.

Click on ‘Activate’ plugin button:

image

Kafka Rule Configuration

Now it’s time to create appropriate Rule.

image

Add filter for POST_TELEMETRY message type:

image

Click ‘Add’ button to add filter.

Then select ‘Kafka Plugin’ in the drop-down box for the Plugin field:

image

Add action that will send temperature telemetry of device to particular kafka topic:

image

Click ‘Add’ button and then activate Rule.

Sending Temperature Telemetry

Now you can send Telemetry message that contains ‘temp’ telemetry for any of your devices:

1
{"temp":73.4}

You should see ‘73.4’ message in appropriate Kafka topic once you’ll post this message.

Here is an example of a command that publish single telemetry message to locally installed ThingsBoard:

1
mosquitto_pub -d -h "localhost" -p 1883 -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -m '{"temp":73.4}'