Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Record metadata is accessible via ProcessorContext that is provided via Processor#init()Transformer#init(), and ValueTransformer#init(). The context object is updated under the hood and contains the metadata for the currently processed record each time process() is   transform(), or transformValue() is called.

Code Block
languagejava
titleAccessing record metadata via ProcessorContext
linenumberstrue
public class MyProcessor implements Processor<KEY_TYPE, VALUE_TYPE> {
  private ProcessorContext context;

  @Override
  public void init(final ProcessorContext context) {
    this.context = context;
  }

  @Override
  void process(final KEY_TYPE key, final VALUE_TYPE value) {
      this.context.offset(); // returns the current record's offset
      // you can also access #partition(), #timestamp(), and #topic()
  }
 
  // other methods omitted for brevity
}

...