title: how to schedule kafka topic message consumptions?
body: <p>I've been working with <code>Apache Kafka</code> and was able to publish and consume messages on my <code>Ubuntu</code> server. So basically I've got my publisher Java program &amp; on the other hand I've got my consumer Java program. </p>
  
  <p>I'm hereby providing the source code for my Consumer <a href="http://pastebin.com/ZzNJkcT1" rel="nofollow">class</a>. I've got somewhat knowledge on <code>scheduling</code> such as <code>Threads</code> and <code>TimerTask</code>. In the source code I'm printing the messages repetitively using a while. </p>
  
  <p>What I want to know is, how could I print, the number of messages (ie: count of the messages) have been consumed within a period of 3 seconds. I've done something like this when I'm publishing the messages:. </p>
  
  <pre><code>TimerTask tasknew = new TimerTask() {
  
  
          @Override
          public void run() {
              System.out.println("count : "+ count);
              count = 0;
  
              for (int i = 1; i &lt; 2100; i++) {
                  count = count + 1;
                  String ip = "192.168.2." + rnd.nextInt(255);
                  String msg = " testing ";
                  KeyedMessage&lt;String, String&gt; data = new KeyedMessage&lt;String, String&gt;("Games", ip , msg);
                  producer.send(data);
  
              }
          }
      };
      Timer timer = new Timer();
      timer.schedule(tasknew, 100, 3000);
  </code></pre>
  
  <p>So what basically this does is to print 700 messages, every three seconds. I need the same to be done when I'm consuming as well. But to show the number of messages that have been consumed within a period of 3 seconds for example. </p>
  
  <p>How can I work it around? Any help would be appreciated. </p>