java.lang.Object
io.cloudevents.kafka.KafkaMessageFactory
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 Summary
Modifier and TypeMethodDescriptionstatic <K> io.cloudevents.core.message.MessageReadercreateReader(ConsumerRecord<K, byte[]> record) Create aMessageReaderto readConsumerRecord.static io.cloudevents.core.message.MessageReadercreateReader(Headers headers, byte[] payload) static io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<Void,byte[]>>, ProducerRecord<Void, byte[]>> createWriter(String topic) 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 aMessageWriterto write aProducerRecord.static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>, ProducerRecord<K, byte[]>> createWriter(String topic, Integer partition, K key) static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>, ProducerRecord<K, byte[]>> createWriter(String topic, K key)
-
Method Details
-
createReader
public static <K> io.cloudevents.core.message.MessageReader createReader(ConsumerRecord<K, byte[]> record) throws io.cloudevents.rw.CloudEventRWExceptionCreate aMessageReaderto readConsumerRecord.- Type Parameters:
K- the type of the record key- Parameters:
record- the record to convert toMessageReader- Returns:
- the new
MessageReader - Throws:
io.cloudevents.rw.CloudEventRWException- if something goes wrong while resolving theSpecVersionor 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[]>>, createWriterProducerRecord<K, byte[]>> (String topic, Integer partition, Long timestamp, K key) Create aMessageWriterto write aProducerRecord.- Type Parameters:
K- the key type- Parameters:
topic- the topic where to write the recordpartition- the partition where to write the recordtimestamp- the timestamp of the recordkey- 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[]>>, createWriterProducerRecord<K, byte[]>> (String topic, Integer partition, K key) -
createWriter
public static <K> io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<K,byte[]>>, createWriterProducerRecord<K, byte[]>> (String topic, K key) -
createWriter
public static io.cloudevents.core.message.MessageWriter<io.cloudevents.rw.CloudEventWriter<ProducerRecord<Void,byte[]>>, createWriterProducerRecord<Void, byte[]>> (String topic)
-