title: consumer.How to specify partition to read? [kafka]
body: <p>I am learning Kafka and I want to know how to specify then partition when I consume messages from a topic.</p>
  <p>I have found several pictures like this:</p>
  <p><a href="https://i.stack.imgur.com/PeZlZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PeZlZ.png" alt="enter image description here" /></a></p>
  <p>It means that a consumer can consume messages from several partitions but a partition can only be read by a single consumer (within a consumer group).</p>
  <p>Also, I have read several examples for consumer and they look like this:</p>
  <pre><code>Properties props = new Properties();
  props.put(&quot;bootstrap.servers&quot;, &quot;localhost:9092&quot;);
  props.put(&quot;group.id&quot;, &quot;consumer-tutorial&quot;);
  props.put(&quot;key.deserializer&quot;, StringDeserializer.class.getName());
  props.put(&quot;value.deserializer&quot;, StringDeserializer.class.getName());
  KafkaConsumer&lt;String, String&gt; consumer = new KafkaConsumer&lt;&gt;(props); 
  </code></pre>
  <p>and:</p>
  <p>Subscribe:</p>
  <pre><code>consumer.subscribe(Arrays.asList(“foo”, “bar”)); 
  </code></pre>
  <p>Poll</p>
  <pre><code> try {
        while (running) {
          ConsumerRecords&lt;String, String&gt; records = consumer.poll(1000);
          for (ConsumerRecord&lt;String, String&gt; record : records)
              System.out.println(record.offset() + &quot;: &quot; + record.value());
        }
   } finally {
        consumer.close();
   }
  </code></pre>
  <p>How does this work? From which partition will I read messages?</p>