You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Laxmi Narayan <ni...@gmail.com> on 2017/03/25 17:35:12 UTC

any way to manually assign listeners to kafka partitions ?

Hi ,
Is there anyway to get the list of all paritions and assign them to
individual java threads for constantly listening ?

Keep learning keep moving .....

Re: any way to manually assign listeners to kafka partitions ?

Posted by BigData dev <bi...@gmail.com>.
There is a method is consumer is used for getting all partitions for a topic
List
<http://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true>
<PartitionInfo
<https://kafka.apache.org/0100/javadoc/org/apache/kafka/common/PartitionInfo.html>
> *partitionsFor
<https://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/Consumer.html#partitionsFor(java.lang.String)>*
(String
<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 topic)

And next assign method can be used to assign the required partitions for
that consumer
void *assign
<https://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/Consumer.html#assign(java.util.Collection)>*
(Collection
<http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true>
<TopicPartition
<https://kafka.apache.org/0100/javadoc/org/apache/kafka/common/TopicPartition.html>
> partitions)
So, in each thread you can use these methods, and do the needful.

Thanks,
Bharat

On Sat, Mar 25, 2017 at 10:35 AM, Laxmi Narayan <ni...@gmail.com>
wrote:

> Hi ,
> Is there anyway to get the list of all paritions and assign them to
> individual java threads for constantly listening ?
>
> Keep learning keep moving .....
>