Skip to main content

Kafka Producer

Purpose

This target publishes variables, devices, alarms, and plugin events to Apache Kafka topics.

Configure the forwarding group and target through Data Forwarding. This page covers Kafka connection, security, Topic templates, and Kafka debug operations.

Open the plugin

Open Development Configuration → Data Forwarding and:

  1. Configure and save the forwarding group range, trigger, interval, online filter, and batching.
  2. Add a target, choose Kafka Producer, and fill in the basic target information.
  3. Open Target properties and configure the Kafka endpoint, security, message, script, and cache settings.
  4. Save and enable the group and target, then use Target debug to verify publishing.

Basic target information

SettingDefaultConfiguration
Group-Select a saved forwarding group.
Target name-Required and unique within the group. Include the environment or cluster name.
EnableEnabledDisable to stop the producer.
Log levelInfoTemporarily use Debug when diagnosing connection or publish errors.
Start timeout60 secondsValid range is 1 to 3600 seconds.

Target properties

Connection

SettingDefaultConfiguration
Service address127.0.0.1:9092Enter Kafka bootstrap servers. Separate multiple nodes with commas, for example kafka-a:9092,kafka-b:9092. Do not include a Topic or protocol prefix.
Publish timeout5000 msPositive timeout for one publish operation. Failures follow the target cache policy.

Security

SettingDefaultConfiguration
UsernameEmptyFill only when the Broker requires SASL.
PasswordEmptySASL password; never place it in screenshots, templates, or logs.
Security protocolPlaintextMatch the Broker listener: Plaintext, Ssl, SaslPlaintext, or SaslSsl.
SASL mechanismPlainMatch the Broker: Gssapi, Plain, ScramSha256, ScramSha512, or OAuthBearer.

Username/password alone do not enable SASL. The protocol, mechanism, and credentials must match the listener as a set.

Message configuration

SettingDefaultConfiguration
Device Topic templateEmptyLeave empty to disable device records, or enter a fixed Topic or ${field} template.
Variable Topic templateThingsGateway/VariableUse a fixed Topic or a template such as ThingsGateway/Variable/${DeviceName}.
Alarm Topic templateEmptyLeave empty to disable alarm records.
Plugin-event Topic templateEmptyLeave empty to disable plugin-event records.

${field} must exist on the corresponding upload entity or script result. A Topic template only controls routing; the forwarding group still controls variable membership.

Target-variable properties

Kafka exposes ten optional text fields, Data1 through Data10, all empty by default. They are stored as target-variable metadata and are not added to Kafka payloads automatically. Leave them empty unless a project-specific script or handler reads them. Configure membership, alias, trigger, and batching in Data Forwarding.

Data and scripts

SettingDefaultConfiguration
Detail logDisabledEnable briefly to inspect each upload or count; keep disabled for high-frequency production.
JSON indentationEnabledDisable to reduce payload size.
Ignore JSON nullsEnabledDisable when null fields must remain in JSON.
Device list uploadEnabledPublish device records as a list; disable for one message per record.
Variable list uploadEnabledPublish variable records as a list; disable for one message per record.
Variable dictionary uploadDisabledApplies only to variable-list mode; groups as DeviceName → Name → Value.
Alarm list uploadEnabledPublish alarm records as a list; disable for one message per record.
Alarm dictionary uploadDisabledApplies only to alarm-list mode; groups by device and variable.
Plugin-event list uploadEnabledPublish plugin events as a list; disable for one message per record.
Device entity scriptEmptySelect a saved script to transform device objects before grouping and serialization.
Variable entity scriptEmptySelect a saved script to transform variable objects before grouping and serialization.
Alarm entity scriptEmptySelect a saved script to transform alarm objects before grouping and serialization.
Plugin-event entity scriptEmptySelect a saved script to transform plugin-event objects before grouping and serialization.

Upload template configuration

For each entity, choose Text or Json and optionally fill a content template. Empty content uses the default JSON serializer.

ConfigurationDefaultConfiguration
Variable mode / contentText / EmptyUse ${field} in the variable body.
Device mode / contentText / EmptyUse ${field} in the device body.
Alarm mode / contentText / EmptyUse ${field} in the alarm body.
Plugin-event mode / contentText / EmptyUse ${field} in the plugin-event body.

Preview the template before saving. JSON mode must produce valid JSON; Text mode does not add quotes or escaping for you.

Available template fields

EntityAvailable fields
VariableId, Name, DeviceName, Value, RawValue, LastSetValue, CollectGroup, CollectTime, CreateTime, ChangeTime, IsOnline, DataType, Unit, RegisterAddress, OtherMethod, Description, ProtectType, RpcWriteEnable, Remark1 to Remark5, ValueInited, IsMemory
DeviceId, Name, ActiveTime, DeviceStatus, PluginName, Description, LastErrorMessage, Remark1 to Remark5
AlarmAlarmId, VariableId, Name, DeviceName, AlarmCode, AlarmLevel, AlarmLimit, AlarmText, RecoveryCode, AlarmTime, EventTime, FinishTime, ConfirmTime, ConfirmText, AlarmType, EventType, Remark1 to Remark5
Plugin eventDeviceName, ObjectValue

An entity script runs before Topic grouping and template rendering, so its output must still contain every referenced field. An entity type with an empty Topic template does not enter the Kafka queue.

Cache and capacity

SettingDefaultConfiguration
Enable failed-write retry cacheDisabledEnable in production to keep failed publishes in local CacheDB and replay them after recovery. When disabled, failed backoff records may be lost.
Cache file maximum rows262144Maximum CacheDB outbox rows; oldest rows are removed after the limit.
Upload chunk size2000Maximum records per write or replay batch. Reduce it for a slow Broker.
Memory queue limit100000Maximum in-memory records before handoff to CacheDB; sustained overload can still discard old data.
Filter offline dataDisabledFilters offline variables when dequeued. The forwarding-group filter also applies.
Upload concurrency1Kafka publishing is protected by one producer lock; keep 1 unless the deployment has been tested under parallel load.

Target debug

Open Development Configuration → Data Forwarding, select the forwarding group and target, and open Debug.

Kafka protocol panel

Kafka Producer protocol debug panel

Use the panel to perform the plugin-specific connection or publish operation and inspect the result.

Verify the target

  1. Confirm the bootstrap server and Kafka security settings.
  2. Use a test Topic and a small JSON payload.
  3. Consume the Topic with a test consumer.
  4. Compare message count, payload, partition, and timestamp.
  5. Check target logs for publish failures, authentication errors, and timeout retries.

Troubleshooting

SymptomCheck
Consumer receives no messageBootstrap server, Topic template, cluster ACL, target state, and consumer group/offset.
Authentication failsSecurity protocol, SASL mechanism, username, password, and broker listener configuration.
Publish times outBroker reachability, partition leader, network latency, publish timeout, and broker load.
Messages go to an unexpected TopicTopic templates, ${key} fields, entity script output, and the actual forwarding group target.
Payload is invalidTemplate preview, JSON syntax, placeholder names, and entity-script output.
Variable metadata is missing from the payloadData1 to Data10 are reserved metadata and are not serialized by Kafka automatically; add them explicitly in a script or upload template.
Failed publishes disappearCheck the failed-write retry cache, CacheDB pending rows, memory queue limit, and cache file maximum rows.