JDBC Driver for Apache Kafka

Build 25.0.9539

ProduceMessage

Publishes a raw message to a specified Kafka topic. This stored procedure enables data producers to send serialized message payloads (for example, JSON or Avro) directly into the message stream for downstream consumers to process.

Minimum Required Inputs

When producing a message, only the Topic input is required:

EXEC ProduceMessage Topic = 'mytopic'

The other properties have the following default behaviors:

  • Partition: The native library determines the partition automatically, taking into account any relevant options from ProducerProperties.
  • KeyText and KeyBytes: If neither of these is provided, the driver produces a message without a key.
  • MessageText and MessageBytes: If neither of these is provided, the driver produces a message without any content.

Omitting the key or message content may make the message unreadable with certain driver settings. For example, setting MessageKeyType to integer may cause read failures with messages that have no keys. TypeDetectionScheme MessageOnly and MessageKeyType Binary are recommended if you need to read messages containing arbitrary content or keys.

KeyText/KeyBytes and MessageText/MessageBytes

The key and message can each be provided either as text or base64-encoded strings. KeyBytes and MessageBytes accept base64-encoded strings. The driver decodes these values into bytes before sending the message to Kafka.

KeyText and MessageText accept any text. The driver encodes these values as UTF-8 before sending the message to Kafka.

For example, the following statement inserts a message with no key and content that is a single NUL byte:

EXEC ProduceMessage Topic = 'mytopic', MessageBytes = 'AA=='

Input

Name Type Required Description
Topic String True Specifies the Kafka topic that contains the message. This input identifies the message stream to which the data record is published.
Partition String False Specifies the partition that the message is assigned to. The partition value must be valid for the specified topic. The native Kafka client automatically assigns a partition when this input is not set.
KeyText String False Specifies the message key that is provided as readable text. The KeyText input defines the human-readable key portion of the Kafka message that determines how messages are partitioned. The value is encoded as UTF-8 before it is sent to Kafka. Do not set KeyText when KeyBytes input is provided.
KeyBytes String False Specifies the message key that is provided as a Base64-encoded binary string. The KeyBytes input defines the binary representation of the same logical key as the KeyText parameter and is used when the key must preserve exact byte content (for example, hashed or serialized identifiers). Do not set KeyBytes when KeyText input is provided.
MessageText String False Specifies the message value that is provided as readable text. The MessageText input defines the human-readable content of the Kafka message that is sent to the specified topic. The value is encoded as UTF-8 before it is sent to Kafka. Do not set MessageText when MessageBytes input is provided. The MessageBytes input represents the same message value in Base64-encoded binary format.
MessageBytes String False Specifies the message value that is provided as a Base64-encoded binary string. The MessageBytes input defines the binary representation of the same message value as the MessageText input parameter and is used when the message content must preserve exact byte content (for example, serialized, compressed, or non-text data). Do not set MessageBytes when the MessageText input is provided.
Message String False Indicates a deprecated input that functions the same as MessageBytes. This input is used only when MessageBytes is not provided. Both MessageBytes and Message input parameters must be omitted to send a message with no content.

Result Set Columns

Name Type Description
PartitionWritten Int Returns the partition that the message is written to. The value is identical to the Partition input when that parameter is specified.
OffsetWritten Long Returns the offset position within the partition where the message is written. This value enables message retrieval or replay from a specific point in the stream.
TimestampWritten Long Returns the UNIX timestamp that represents the exact instant when the message is committed to the partition.
KeyWritten String Returns the Base64-encoded data of the key that is written. This output is null when neither KeyText nor KeyBytes is provided.
MessageWritten String Returns the Base64-encoded data of the message value that is written. This output is null when neither MessageText nor MessageBytes is provided.
Success Bool Returns a value of 'true' when the stored procedure successfully writes the message to Kafka and a value of 'false' when the operation fails due to invalid parameters or broker-level errors.

Copyright (c) 2026 CData Software, Inc. - All rights reserved.
Build 25.0.9539