kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject [kafka] branch trunk updated: KAFKA-7326: KStream.print() should flush on each line for PrintStream (#5579)
Date Sat, 01 Sep 2018 16:48:58 GMT
This is an automated email from the ASF dual-hosted git repository.

guozhang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new aa7358e  KAFKA-7326: KStream.print() should flush on each line for PrintStream (#5579)
aa7358e is described below

commit aa7358e8cc0305dd9051fe0d281913247a39264d
Author: huxi <huxi_2b@hotmail.com>
AuthorDate: Sun Sep 2 00:48:50 2018 +0800

    KAFKA-7326: KStream.print() should flush on each line for PrintStream (#5579)
    
    Reviewers: Matthias J. Sax <matthias@confluent.io>, Guozhang Wang <guozhang@confluent.io>,
Bill Bejeck <bill@confluent.io>, Kamal Chandraprakash <kamal.chandraprakash@gmail.com>
---
 docs/streams/developer-guide/dsl-api.html                              | 1 +
 streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java    | 3 +++
 .../org/apache/kafka/streams/kstream/internals/PrintForeachAction.java | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/docs/streams/developer-guide/dsl-api.html b/docs/streams/developer-guide/dsl-api.html
index f61f052..01931c8 100644
--- a/docs/streams/developer-guide/dsl-api.html
+++ b/docs/streams/developer-guide/dsl-api.html
@@ -654,6 +654,7 @@
                             caveats.
                             (<a class="reference external" href="../../../javadoc/org/apache/kafka/streams/kstream/KStream.html#print--">details</a>)</p>
                             <p>Calling <code class="docutils literal"><span
class="pre">print()</span></code> is the same as calling <code class="docutils
literal"><span class="pre">foreach((key,</span> <span class="pre">value)</span>
<span class="pre">-&gt;</span> <span class="pre">System.out.println(key</span>
<span class="pre">+</span> <span class="pre">&quot;,</span> <span
class="pre">&quot;</span> <span class="pre">+</span> <span class="pre">value))</span></code></p>
+                            <p><code class="docutils literal"><span class="pre">print</span></code>
is mainly for debugging/testing purposes, and it will try to flush on each record print. Hence
it <strong>should not</strong> be used for production usage if performance requirements
are concerned.</p>
                             <div class="last highlight-java"><div class="highlight"><pre><span></span><span
class="n">KStream</span><span class="o">&lt;</span><span class="kt">byte</span><span
class="o">[],</span> <span class="n">String</span><span class="o">&gt;</span>
<span class="n">stream</span> <span class="o">=</span> <span class="o">...;</span>
 <span class="c1">// print to sysout</span>
 <span class="n">stream</span><span class="o">.</span><span class="na">print</span><span
class="o">();</span>
diff --git a/streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java b/streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
index ae3b28a..cf2ce75 100644
--- a/streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
+++ b/streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
@@ -359,6 +359,9 @@ public interface KStream<K, V> {
 
     /**
      * Print the records of this KStream using the options provided by {@link Printed}
+     * Note that this is mainly for debugging/testing purposes, and it will try to flush
on each record print.
+     * It <em>SHOULD NOT</em> be used for production usage if performance requirements
are concerned.
+     *
      * @param printed options for printing
      */
     void print(final Printed<K, V> printed);
diff --git a/streams/src/main/java/org/apache/kafka/streams/kstream/internals/PrintForeachAction.java
b/streams/src/main/java/org/apache/kafka/streams/kstream/internals/PrintForeachAction.java
index 174319f..861dfd3 100644
--- a/streams/src/main/java/org/apache/kafka/streams/kstream/internals/PrintForeachAction.java
+++ b/streams/src/main/java/org/apache/kafka/streams/kstream/internals/PrintForeachAction.java
@@ -51,6 +51,9 @@ public class PrintForeachAction<K, V> implements ForeachAction<K,
V> {
     public void apply(final K key, final V value) {
         final String data = String.format("[%s]: %s", label, mapper.apply(key, value));
         printWriter.println(data);
+        if (!closable) {
+            printWriter.flush();
+        }
     }
 
     public void close() {


Mime
View raw message