title: Need to print the send messages to 10 partitions randomly using kafka
body: <p>Hi I am using Kafka API 0.10.0.1 . I have created the topic kartik and has 10 partitions. From this producer code I am getting output as all the 10 messages are going 10 partitions. But the problem is each partition is getting 10 messages. What I want is each partitions should get only one message i.e. the partitions should get 1  message randomly . Or if we have 50 messages then these messages should be allocated to these partitions randomly, not that each partition gets 50 messages.</p>
  
  <p>public class Producerpar {</p>
  
  <pre><code>public static void main(String[] args) throws Exception{
  
        String topic = "kartik";
        if(topic == null){
           System.out.println("there has to be some topic");
          return;
        }
  
   Properties props = new Properties();
   props.put("bootstrap.servers", "localhost:9092");
   props.put("acks", "all");
   props.put("retries", 0);
   props.put("batch.size", 16384);
   props.put("linger.ms", 1);
   props.put("buffer.memory", 33554432);
   props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
   props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
  
  
  
   Producer&lt;String, String&gt; producer = new KafkaProducer&lt;String, String&gt;(props); 
  
  String msg = "Hey there .. How are you doing ?";    
  for(int i = 0; i &lt; 10; i++) {
  
      List&lt;PartitionInfo&gt; infoList = producer.partitionsFor(topic);
      for(PartitionInfo partitioninfo : infoList){ 
      System.out.println(partitioninfo.partition());
  
  
      producer.send(new ProducerRecord&lt;String, String&gt;(topic, Integer.toString(i), Integer.toString(i)));
  
  
   System.out.println("Message:  " + msg +  " are sent to partitions: " +partitioninfo.partition()  );
  
  
   }
  </code></pre>
  
  <p>}</p>