Route Kafka messages by partition to treatment logic

messagingMarketingRecipe Tools

What it does

When a new message arrives in a Kafka topic, this automation filters by partition and routes valid messages to treatment logic. It monitors for errors and updates the result variable so someone knows the outcome.

Who it's for

Engineering teams who need to process Kafka messages from a specific partition and handle errors in real time.

How teams use this

Process messages from the primary partition

Filter incoming Kafka messages so only those from partition zero reach the treatment function. This ensures the team processes data from the correct source without manual intervention.

Route messages to different treatment flows

Modify the partition condition to target a different partition ID and point to a separate treatment function. The structure stays the same and only the condition and function change.

Add logging for discarded messages

Include a step that logs partition IDs when messages are discarded so the team can audit which partitions were filtered out and why.

How it works

  1. Listen for new Kafka messages. Monitor a Kafka topic for new messages in real time and pass each one to the next step for evaluation.
  2. Check if message is from partition zero. Evaluate the partition ID on the incoming message. If it does not equal zero, stop the job. If it matches, continue to treatment logic.
  3. Invoke treatment function. Call the treatment function to process the message and capture the output in a result variable for downstream evaluation.
  4. Check treatment output for errors. Examine the result variable to see if the treatment function returned an error. If yes, stop the job with that error. If no, update the result and complete.