alexeyt820 commented on a change in pull request #6615: [FLINK-8354] 
[flink-connectors] Add ability to access and provider Kafka headers
URL: https://github.com/apache/flink/pull/6615#discussion_r250282725
 
 

 ##########
 File path: 
flink-connectors/flink-connector-kafka-base/src/main/java/org/apache/flink/streaming/util/serialization/KeyedSerializationSchema.java
 ##########
 @@ -55,4 +57,13 @@
         * @return null or the target topic
         */
        String getTargetTopic(T element);
+
+       /**
+        *
+        * @param element The incoming element to be serialized
+        * @return collection of headers (maybe empty)
+        */
+       default Iterable<Map.Entry<String, byte[]>> headers(T element) {
 
 Review comment:
   I can try to use ProducerRecord by adding factory method to 
KeyedSerializationSchema
   ```suggestion
   interface KeyedSerializationSchema {
   ...
        default ProducerRecord<byte[], byte[]> newProducerRecord(T element, 
        byte[] serializedKey, byte[] serializedValue, Integer partition, String 
topic, Long timestamp) {
                return new ProducerRecord<>(topic, partition, timestamp, 
serializedKey, serializedValue);
        }
   }
   ```
   And then in a producer:
   ```suggestion
        String targetTopic = schema.getTargetTopic(next);
        if (targetTopic == null) {
                targetTopic = defaultTopicId;
        }
        ...
        ProducerRecord<byte[], byte[]> record = schema.newProducerRecord(
          next, 
          serializedKey,
          serializedValue
          flinkKafkaPartitioner != null ?
                flinkKafkaPartitioner.partition(next, serializedKey, 
serializedValue, targetTopic, partitions) : null,
          targetTopic, 
          timestamp);
          ...
   ```
   Note that we can't deprecate getTargetTopic, serializeKey and 
serializedValue, because they are used by partitioner as well.
   
   What do you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to