muralibasani commented on code in PR #21676:
URL: https://github.com/apache/kafka/pull/21676#discussion_r3564478085
##########
clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java:
##########
@@ -81,6 +83,35 @@ public ProducerRecord(String topic, Integer partition, Long
timestamp, K key, V
this.value = value;
this.timestamp = timestamp;
this.headers = new RecordHeaders(headers);
+ this.rawSerializedHeaders = null;
+ }
+
+ /**
+ * Creates a record carrying pre-serialized header bytes. When this
constructor is used, the
+ * producer writes {@code rawSerializedHeaders} directly into the record
batch without
+ * deserializing or re-serializing individual headers. The {@code
rawSerializedHeaders} must
+ * use the standard Kafka header wire format: {@code
[count(varint)][header1][header2]...},
+ * or be empty (length 0) for zero headers.
+ *
+ * <p>This is intended for internal use (e.g., Kafka Streams changelog
writing) where headers
+ * are already available in serialized form and the deserialization
round-trip should be avoided.
+ */
+ public ProducerRecord(String topic, Integer partition, Long timestamp, K
key, V value, byte[] rawSerializedHeaders) {
+ if (topic == null)
+ throw new IllegalArgumentException("Topic cannot be null.");
+ if (timestamp != null && timestamp < 0)
+ throw new IllegalArgumentException(
+ String.format("Invalid timestamp: %d. Timestamp should
always be non-negative or null.", timestamp));
+ if (partition != null && partition < 0)
+ throw new IllegalArgumentException(
+ String.format("Invalid partition: %d. Partition number
should always be non-negative or null.", partition));
+ this.topic = topic;
+ this.partition = partition;
+ this.key = key;
+ this.value = value;
+ this.timestamp = timestamp;
+ this.headers = new RecordHeaders();
Review Comment:
Yes, good point.the new approach indeed fixes that trap. record.headers()
now returns the PreSerializedHeaders instance itself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]