Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-4691

ProducerInterceptor.onSend() is called after key and value are serialized

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.10.1.1
    • None
    • clients, streams
    • None

    Description

      According to the JavaDoc (https://kafka.apache.org/0101/javadoc/org/apache/kafka/clients/producer/ProducerInterceptor.html) " This is called from KafkaProducer.send(ProducerRecord) and KafkaProducer.send(ProducerRecord, Callback) methods, before key and value get serialized and partition is assigned (if partition is not specified in ProducerRecord)".

      Although when using this with Kafka Streams (StreamsConfig.producerPrefix(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG)) the key and value contained in the record object are already serialized.

      As you can see from the screenshot, the serialization is performed inside RecordCollectionImpl.send(ProducerRecord<K, V> record, Serializer<K> keySerializer, Serializer<V> valueSerializer,
      StreamPartitioner<K, V> partitioner), effectively before calling the send method of the producer which will trigger the interceptor.

      This makes it unable to perform any kind of operation involving the key or value of the message, unless at least performing an additional deserialization.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            francescolemma Francesco Lemma
            francescolemma Francesco Lemma
            Anna Povzner Anna Povzner

            Dates

              Created:
              Updated:

              Slack

                Issue deployment