mirror of https://github.com/apache/kafka.git
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>
This commit is contained in:
parent
4f38c8cd60
commit
aa7358e8cc
|
@ -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">-></span> <span class="pre">System.out.println(key</span> <span class="pre">+</span> <span class="pre">",</span> <span class="pre">"</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"><</span><span class="kt">byte</span><span class="o">[],</span> <span class="n">String</span><span class="o">></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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue