Skip to content

Commit c140cbc

Browse files
committed
nits
1 parent 147cd04 commit c140cbc

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoDeserializer.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* deserialization of byte arrays into Proto message objects by utilizing the provided Parser for
1414
* the specific Proto message type.
1515
*
16-
* <p>Motivation: In setups where both producers and consumers use the same Proto schemas, the need
17-
* for schema validation becomes redundant. The built-in {@code kafkaProtoSerdes} from Confluent
18-
* performs schema validation via the schema registry service, which introduces overhead. This
19-
* custom deserializer eliminates that overhead, simplifying the processing flow by bypassing schema
20-
* validation.
21-
*
16+
* <p>Motivation: Since the proto. configurations are usually shared between the producer and the
17+
* consumers,the field descriptors are well-known to both the parties. In cases when there are other
18+
* mechanisms to validate proto. compatibilities schema validation becomes redundant and this class
19+
* can be used in such cases. The built-in {@code kafkaProtoSerdes} from Confluent performs schema
20+
* validation via the schema registry service, which introduces overhead. This custom deserializer
21+
* eliminates that overhead, simplifying the processing flow by bypassing schema validation.
2222
*
2323
* <p>Usage: To use this class, create a subclass specifying the Proto message type, pass the
2424
* corresponding Parser to the superclass constructor, and configure Kafka to use the custom

kafka-streams-serdes/src/main/java/org/hypertrace/core/kafkastreams/framework/serdes/proto/ProtoSerializer.java

+34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@
33
import com.google.protobuf.Message;
44
import org.apache.kafka.common.serialization.Serializer;
55

6+
/**
7+
* Custom Proto Serializer for Kafka.
8+
*
9+
* <p>This class provides a serialization mechanism for Kafka messages using Protocol Buffers
10+
* without schema validation. It extends the Kafka Serializer interface and allows for direct
11+
* serialization of byte arrays into Proto message objects by utilizing the provided Parser for the
12+
* specific Proto message type.
13+
*
14+
* <p>Motivation: Since the proto. configurations are usually shared between the producer and the
15+
* consumers,the field descriptors are well-known to both the parties. In cases when there are other
16+
* mechanisms to validate proto. compatibilities schema validation becomes redundant and this class
17+
* can be used in such cases. The built-in {@code kafkaProtoSerdes} from Confluent performs schema
18+
* validation via the schema registry service, which introduces overhead. This custom serializer
19+
* eliminates that overhead, simplifying the processing flow by bypassing schema validation.
20+
*
21+
* <p>Usage: To use this class, create a subclass specifying the Proto message type, and configure
22+
* Kafka to use the custom serializer.
23+
*
24+
* <p>Example:
25+
*
26+
* <pre>{@code
27+
* public class MyProtoMessageSerializer extends ProtoSerializer<MyProtoMessage> {
28+
*
29+
* }
30+
* }</pre>
31+
*
32+
* Then, configure Kafka to use this serializer:
33+
*
34+
* <pre>{@code
35+
* key.serializer=com.example.MyProtoMessageSerializer
36+
* }</pre>
37+
*
38+
* @param <T> The Proto message type to be serialized.
39+
*/
640
public class ProtoSerializer<T extends Message> implements Serializer<T> {
741
@Override
842
public byte[] serialize(String topic, T data) {

0 commit comments

Comments
 (0)