title: Stream API and Queues: Subscribe to BlockingQueue stream-style
body: <p>Let's say we have a Queue</p>
  
  <pre><code>BlockingQueue&lt;String&gt; queue= new LinkedBlockingQueue&lt;&gt;();
  </code></pre>
  
  <p>and some other thread puts values in it, then we read it like</p>
  
  <pre><code>while (true) {
      String next = queue.take();
      System.out.println("next message:" + next);
  }
  </code></pre>
  
  <p>How can I iterate over this queue in stream style, while maintaining similar semantics to above code.</p>
  
  <p>This code only traverses the current queue state:</p>
  
  <pre><code>queue.stream().forEach(e -&gt; System.out.println(e));
  </code></pre>