title: Attaching KafaConsumer assigned to a specific partition
body: <p>How to attach a python consumer script to a particular kafka partition. <br> 
  On running two instance of the consumer script (given below), each of them randomly picks up one partition and then consumes/prints all messages of that particular partition, As expected.<br><br>
  But as I need to output these messages to a partition named local file on disk, attaching each instance of the script to a pre declared partition ID would make things easier  <br>
  file name eg. : </p>
  
  <pre><code>Date/Hour/PARTITION_ID-0.CSV
  Date/Hour/PARTITION_ID-1.CSV
  </code></pre>
  
  <p>Any idea on how to achieve that. <br>
  Feel free to suggest alternatives approaches. </p>
  
  <p>Kafka Setup: </p>
  
  <pre><code>Topic:my-topic3 PartitionCount:2    ReplicationFactor:2 Configs:
  Topic: my-topic3    Partition: 0    Leader: 2   Replicas: 2,1   Isr: 2,1
  Topic: my-topic3    Partition: 1    Leader: 1   Replicas: 1,2   Isr: 1,2
  </code></pre>
  
  <p>Kafka Consumer Script ( in python ) [ <strong>WITH FIX</strong> ] </p>
  
  <pre><code>from kafka import KafkaConsumer
  from kafka import TopicPartition
  
  # To consume latest messages and auto-commit offsets
  #consumer = KafkaConsumer('my-topic3',
  #                         group_id='my-group',
  #                         bootstrap_servers=['192.168.150.80:9092'])
  
  # To consume messages from a specific PARTITION  [ FIX ]
  consumer = KafkaConsumer(bootstrap_servers='192.168.150.80:9092')
  consumer.assign([TopicPartition('my-topic3', 1)])
  
  for message in consumer:
      # message value and key are raw bytes -- decode if necessary!
      # e.g., for unicode: `message.value.decode('utf-8')`
      print ("Topic= %s : Partition= %d : Offset= %d: key= %s value= %s" % (message.topic, message.partition,
                                            message.offset, message.key,
                                            message.value))
  </code></pre>
  
  <p><strong>Update</strong> : As suggested below , i used assign function, but kept on getting illegal state error  <br>
  assign function</p>
  
  <pre><code>consumer.assign([TopicPartition('my-topic3',1)])
  </code></pre>
  
  <p>Error </p>
  
  <pre><code>    Traceback (most recent call last):
    File "consumerExample.py", line 13, in &lt;module&gt;
      consumer.assign([TopicPartition('my-topic3',1)])
    File "/usr/lib/python2.7/site-packages/kafka/consumer/group.py", line 278, in assign
      self._subscription.assign_from_user(partitions)
    File "/usr/lib/python2.7/site-packages/kafka/consumer/subscription_state.py", line 189, in assign_from_user
      raise IllegalStateError(self._SUBSCRIPTION_EXCEPTION_MESSAGE)
  kafka.errors.IllegalStateError: You must choose only one way to configure
  </code></pre>