From c140cbc869d28361a688c1e145c85c94481525bc Mon Sep 17 00:00:00 2001 From: singh-viikram Date: Thu, 12 Sep 2024 18:04:29 +0530 Subject: [PATCH] nits --- .../serdes/proto/ProtoDeserializer.java | 12 +++---- .../serdes/proto/ProtoSerializer.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoDeserializer.java b/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoDeserializer.java index c2855b8..0280894 100644 --- a/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoDeserializer.java +++ b/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoDeserializer.java @@ -13,12 +13,12 @@ * deserialization of byte arrays into Proto message objects by utilizing the provided Parser for * the specific Proto message type. * - *

Motivation: In setups where both producers and consumers use the same Proto schemas, the need - * for schema validation becomes redundant. The built-in {@code kafkaProtoSerdes} from Confluent - * performs schema validation via the schema registry service, which introduces overhead. This - * custom deserializer eliminates that overhead, simplifying the processing flow by bypassing schema - * validation. - * + *

Motivation: Since the proto. configurations are usually shared between the producer and the + * consumers,the field descriptors are well-known to both the parties. In cases when there are other + * mechanisms to validate proto. compatibilities schema validation becomes redundant and this class + * can be used in such cases. The built-in {@code kafkaProtoSerdes} from Confluent performs schema + * validation via the schema registry service, which introduces overhead. This custom deserializer + * eliminates that overhead, simplifying the processing flow by bypassing schema validation. * *

Usage: To use this class, create a subclass specifying the Proto message type, pass the * corresponding Parser to the superclass constructor, and configure Kafka to use the custom diff --git a/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoSerializer.java b/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoSerializer.java index 0d1754f..edc86eb 100644 --- a/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoSerializer.java +++ b/kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoSerializer.java @@ -3,6 +3,40 @@ import com.google.protobuf.Message; import org.apache.kafka.common.serialization.Serializer; +/** + * Custom Proto Serializer for Kafka. + * + *

This class provides a serialization mechanism for Kafka messages using Protocol Buffers + * without schema validation. It extends the Kafka Serializer interface and allows for direct + * serialization of byte arrays into Proto message objects by utilizing the provided Parser for the + * specific Proto message type. + * + *

Motivation: Since the proto. configurations are usually shared between the producer and the + * consumers,the field descriptors are well-known to both the parties. In cases when there are other + * mechanisms to validate proto. compatibilities schema validation becomes redundant and this class + * can be used in such cases. The built-in {@code kafkaProtoSerdes} from Confluent performs schema + * validation via the schema registry service, which introduces overhead. This custom serializer + * eliminates that overhead, simplifying the processing flow by bypassing schema validation. + * + *

Usage: To use this class, create a subclass specifying the Proto message type, and configure + * Kafka to use the custom serializer. + * + *

Example: + * + *

{@code
+ * public class MyProtoMessageSerializer extends ProtoSerializer {
+ *
+ * }
+ * }
+ * + * Then, configure Kafka to use this serializer: + * + *
{@code
+ * key.serializer=com.example.MyProtoMessageSerializer
+ * }
+ * + * @param The Proto message type to be serialized. + */ public class ProtoSerializer implements Serializer { @Override public byte[] serialize(String topic, T data) {