Class KafkaMessageFactory

java.lang.Object
io.cloudevents.kafka.KafkaMessageFactory

@ParametersAreNonnullByDefault public final class KafkaMessageFactory extends Object
This class provides a collection of methods to create MessageReader and MessageWriter for Kafka Producer and Consumer.

These can be used as an alternative to CloudEventDeserializer and CloudEventSerializer to manually serialize/deserialize CloudEvent messages.

  • Method Details

    • createReader

      public static <K> io.cloudevents.core.message.MessageReader createReader(ConsumerRecord<K,byte[]> record) throws io.cloudevents.rw.CloudEventRWException
      Create a MessageReader to read ConsumerRecord.
      Type Parameters:
      K - the type of the record key
      Parameters:
      record - the record to convert to MessageReader
      Returns:
      the new MessageReader
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something goes wrong while resolving the SpecVersion or if the message has unknown encoding
    • createReader

      public static io.cloudevents.core.message.MessageReader createReader(Headers headers, byte[] payload) throws io.cloudevents.rw.CloudEventRWException
      Throws:
      io.cloudevents.rw.CloudEventRWException
      See Also:
    • createWriter

      public static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>,ProducerRecord<K,byte[]>> createWriter(String topic, Integer partition, Long timestamp, K key)
      Create a MessageWriter to write a ProducerRecord.
      Type Parameters:
      K - the key type
      Parameters:
      topic - the topic where to write the record
      partition - the partition where to write the record
      timestamp - the timestamp of the record
      key - the key of the record
      Returns:
      the new MessageWriter
    • createWriter

      public static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>,ProducerRecord<K,byte[]>> createWriter(String topic, Integer partition, K key)
      See Also:
    • createWriter

      public static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>,ProducerRecord<K,byte[]>> createWriter(String topic, K key)
      See Also:
    • createWriter

      public static io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<Void,byte[]>>,ProducerRecord<Void,byte[]>> createWriter(String topic)
      See Also: