Class Envelope

java.lang.Object
io.debezium.data.Envelope

public final class Envelope extends Object
An immutable descriptor for the structure of Debezium message envelopes. An Envelope can be created for each message schema using the defineSchema() builder, and once created can generate Struct objects representing CREATE, READ, UPDATE, and DELETE messages that conform to that schema.
Author:
Randall Hauch
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A builder of an envelope schema.
    static final class 
    The constants for the names of the fields in the message envelope.
    static enum 
    The constants for the values for the operation field in the message envelope.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Set<String>
    The immutable set of all Envelope.FieldNames.
    static final boolean
    Flag that specifies whether the Envelope.FieldName.OPERATION field is required within the envelope.
    private final org.apache.kafka.connect.data.Schema
     
    static String
    A suffix appended to each schema name representing Envelope
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Envelope(org.apache.kafka.connect.data.Schema schema)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.kafka.connect.data.Struct
    create(Object record, org.apache.kafka.connect.data.Struct source, Instant timestamp)
    Generate a create message with the given information.
     
    org.apache.kafka.connect.data.Struct
    delete(Object before, org.apache.kafka.connect.data.Struct source, Instant timestamp)
    Generate an delete message with the given information.
    static Envelope
    fromSchema(org.apache.kafka.connect.data.Schema schema)
     
    static boolean
     
    static boolean
    isEnvelopeSchema(org.apache.kafka.connect.data.Schema schema)
     
    operationFor(org.apache.kafka.connect.source.SourceRecord record)
    Obtain the operation for the given source record.
    org.apache.kafka.connect.data.Struct
    read(Object record, org.apache.kafka.connect.data.Struct source, Instant timestamp)
    Generate a read message with the given information.
    org.apache.kafka.connect.data.Schema
    Get the Schema describing the message envelopes and their content.
    static String
    Converts an event type name into envelope schema name
    org.apache.kafka.connect.data.Struct
    truncate(org.apache.kafka.connect.data.Struct source, Instant timestamp)
    Generate an truncate message with the given information.
    org.apache.kafka.connect.data.Struct
    update(Object before, org.apache.kafka.connect.data.Struct after, org.apache.kafka.connect.data.Struct source, Instant timestamp)
    Generate an update message with the given information.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SCHEMA_VERSION

      public static final int SCHEMA_VERSION
      See Also:
    • OPERATION_REQUIRED

      public static final boolean OPERATION_REQUIRED
      Flag that specifies whether the Envelope.FieldName.OPERATION field is required within the envelope.
      See Also:
    • ALL_FIELD_NAMES

      public static final Set<String> ALL_FIELD_NAMES
      The immutable set of all Envelope.FieldNames.
    • SCHEMA_NAME_SUFFIX

      public static String SCHEMA_NAME_SUFFIX
      A suffix appended to each schema name representing Envelope
    • schema

      private final org.apache.kafka.connect.data.Schema schema
  • Constructor Details

    • Envelope

      public Envelope(org.apache.kafka.connect.data.Schema schema)
  • Method Details

    • defineSchema

      public static Envelope.Builder defineSchema()
    • fromSchema

      public static Envelope fromSchema(org.apache.kafka.connect.data.Schema schema)
    • schema

      public org.apache.kafka.connect.data.Schema schema()
      Get the Schema describing the message envelopes and their content.
      Returns:
      the schema; never null
    • read

      public org.apache.kafka.connect.data.Struct read(Object record, org.apache.kafka.connect.data.Struct source, Instant timestamp)
      Generate a read message with the given information.
      Parameters:
      record - the state of the record as read; may not be null
      source - the information about the source that was read; may be null
      timestamp - the timestamp for this message; may be null
      Returns:
      the read message; never null
    • create

      public org.apache.kafka.connect.data.Struct create(Object record, org.apache.kafka.connect.data.Struct source, Instant timestamp)
      Generate a create message with the given information.
      Parameters:
      record - the state of the record after creation; may not be null
      source - the information about the source where the creation occurred; may be null
      timestamp - the timestamp for this message; may be null
      Returns:
      the create message; never null
    • update

      public org.apache.kafka.connect.data.Struct update(Object before, org.apache.kafka.connect.data.Struct after, org.apache.kafka.connect.data.Struct source, Instant timestamp)
      Generate an update message with the given information.
      Parameters:
      before - the state of the record before the update; may be null
      after - the state of the record after the update; may not be null
      source - the information about the source where the update occurred; may be null
      timestamp - the timestamp for this message; may be null
      Returns:
      the update message; never null
    • delete

      public org.apache.kafka.connect.data.Struct delete(Object before, org.apache.kafka.connect.data.Struct source, Instant timestamp)
      Generate an delete message with the given information.
      Parameters:
      before - the state of the record before the delete; may be null
      source - the information about the source where the deletion occurred; may be null
      timestamp - the timestamp for this message; may be null
      Returns:
      the delete message; never null
    • truncate

      public org.apache.kafka.connect.data.Struct truncate(org.apache.kafka.connect.data.Struct source, Instant timestamp)
      Generate an truncate message with the given information.
      Parameters:
      source - the information about the source where the truncate occurred; never null
      timestamp - the timestamp for this message; never null
      Returns:
      the truncate message; never null
    • operationFor

      public static Envelope.Operation operationFor(org.apache.kafka.connect.source.SourceRecord record)
      Obtain the operation for the given source record.
      Parameters:
      record - the source record; may not be null
      Returns:
      the operation, or null if no valid operation was found in the record
    • schemaName

      public static String schemaName(String type)
      Converts an event type name into envelope schema name
      Parameters:
      type -
      Returns:
      Envelope schema name
    • isEnvelopeSchema

      public static boolean isEnvelopeSchema(String schemaName)
      Parameters:
      schemaName -
      Returns:
      true if schema name conforms to Envelope naming
    • isEnvelopeSchema

      public static boolean isEnvelopeSchema(org.apache.kafka.connect.data.Schema schema)
      Parameters:
      schema -
      Returns:
      true if schema name conforms to Envelope naming