Class CloudEventSerializer

java.lang.Object
io.cloudevents.kafka.CloudEventSerializer
All Implemented Interfaces:
Closeable, AutoCloseable, Serializer<io.cloudevents.CloudEvent>

public class CloudEventSerializer extends Object implements Serializer<io.cloudevents.CloudEvent>
Kafka Serializer for CloudEvent.

To configure the encoding to use when serializing the event, you can use the ENCODING_CONFIG configuration key, which accepts both a String or a variant of the enum Encoding. If you configure the Encoding as Encoding.STRUCTURED, you MUST configure the EventFormat to use with EVENT_FORMAT_CONFIG, specifying a String corresponding to the content type of the event format or specifying an instance of EventFormat.

  • Field Details

    • ENCODING_CONFIG

      public static final String ENCODING_CONFIG
      The configuration key for the Encoding to use when serializing the event.
      See Also:
    • EVENT_FORMAT_CONFIG

      public static final String EVENT_FORMAT_CONFIG
      The configuration key for the EventFormat to use when serializing the event in structured mode.
      See Also:
  • Constructor Details

    • CloudEventSerializer

      public CloudEventSerializer()
  • Method Details

    • configure

      public void configure(Map<String,?> configs, boolean isKey)
      Specified by:
      configure in interface Serializer<io.cloudevents.CloudEvent>
    • serialize

      public byte[] serialize(String topic, io.cloudevents.CloudEvent data)
      Specified by:
      serialize in interface Serializer<io.cloudevents.CloudEvent>
    • serialize

      public byte[] serialize(String topic, Headers headers, io.cloudevents.CloudEvent data)
      Specified by:
      serialize in interface Serializer<io.cloudevents.CloudEvent>