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

Let KStream.print() to flush on each printed line

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.1.0
    • Component/s: streams
    • Labels:

      Description

      Today, KStream.print() is implemented as a special "foreach" function as below:

      @Override
          public void apply(final K key, final V value) {
              final String data = String.format("[%s]: %s", label, mapper.apply(key, value));
              printWriter.println(data);
          }
      

      Note that since this.printWriter = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));, without flushing the writer we do not guarantee that printed lines are written to the underlying `outputStream` in time.

      Since KStream.print() is mainly for debugging / testing / demoing purposes, not for performance, I think it is okay to enforce auto flushing.

      This would include:

      1. set autoFlush in the constructor of printWriter.
      2. document in java-docs of KStream.print that this is for debug / testing purposes only, and it will try to flush on each record print, and hence should not be used for production usage if performance requirement is key.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                huxi_2b huxihx
                Reporter:
                guozhang Guozhang Wang
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: