Skip to main content
Dependencies:
  • ProphecySparkBasicsPython 0.2.49+
  • ProphecySparkBasicsScala 0.0.1+
  • ProphecyLibsPython 1.9.24+
Cluster requirements:
  • UC dedicated clusters not supported
  • UC standard clusters 14.3+ supported
  • Livy clusters not supported
The Kafka file type is used in Apache Kafka. Read and write Kafka files using a Source or Target gem.

Source

The Source gem reads data from Kafka stream in batch mode and allows you to optionally specify the following additional properties. This means that Kafka only reads data incrementally from the last offset stored in the specified Metadata table. If the Metadata table is not present, then Kafka reads data from the earliest offset.

Source location

Source properties

Example

Example usage of Filter

Compiled code

To see the compiled code of your project, switch to the Code view in the project header.

Target

The Target gem writes data to each row from the Dataframe to a Kafka topic as JSON messages and allows you to optionally specify the following additional properties.

Target location

Target properties

Example

Example usage of Filter

Compiled code

To see the compiled code of your project, switch to the Code view in the project header.

Example Pipeline

Source Pipeline Example

In this example, you read JSON messages from Kafka, parse them, remove any null messages, and persist the data to a Delta table. Example usage of Filter
To see the compiled code of your project, switch to the Code view in the project header.

Metadata Table

To avoid reprocessing messages on subsequent pipeline runs, update a table with the last processed offsets for each Kafka partition and topic. When you run the pipeline, the table only gets a batch of messages that arrived since the previously-processed offset. In this example, you update metadata.kafka_offsets, which has the following structure: Taking this approach provides you the with following benefits:
  1. Builds the pipeline interactively without committing any offsets.
  2. Production workflows only consume messages that arrived since the previously-processed offset.
  3. You can replay old messages by modifying the Metadata table.
For production workflows the phase for the Script gem that updates the offsets should be greater than the phase of the Target gem. This ensures that offsets only update in the table after Prophecy safely persists the data to the Target.

Spark Code used for script component

To see the compiled code of your project, switch to the Code view in the project header.