node.js - Understanding Kafka Partition Metadata -


i usign kafka-node within nodejs application create topics via loadmetadatafortopics option. want application dynamically understand number of partitions avaiable can distribute messages across partitions.

in single node kafka instance method creating topics , returning metadata this:

  "step1_channelout": {     "0": {       "topic": "step1_channelout",       "partition": 0,       "leader": 1,       "replicas": [         1       ],       "isr": [         1       ]     }   }, 

however in 3 node cluster, method creates more entries:

{     "0": {         "topic": "step1_channelout",         "partition": 0,         "leader": 3,         "replicas": [             3,             2,             1         ],         "isr": [             3,             2,             1         ]     },     "1": {         "topic": "step1_channelout",         "partition": 1,         "leader": 1,         "replicas": [             1,             3,             2         ],         "isr": [             1,             3,             2         ]     },     "2": {         "topic": "step1_channelout",         "partition": 2,         "leader": 2,         "replicas": [             2,             1,             3         ],         "isr": [             2,             1,             3         ]     },     "3": {         "topic": "step1_channelout",         "partition": 3,         "leader": 3,         "replicas": [             3,             1,             2         ],         "isr": [             3,             1,             2         ]     } } 

in case did create 4 partitions? looks me - since last case scenario (really set partitions explicitly) dont care long predictable. said more control have better.

what relationship between topic information in zookeeper versus on kafka server? there bettet way manipulate (create / configure topics) kafka cluster via nodejs?

why 4 partitions? understand three, or one, four?

the way kafka-node works, creates topics based on global kafka configuration found in server.properties. check values of:

num.partitions=12 default.replication.factor=1 

there's no automatic relation between number of brokers , number of partitions. can have 100 broker setup want 1 partition topics, or can have single broker setup 1,000 partitions. not related.

there's no non-java api creating topics -- @ least not yet. see unanswered question here.

if want more control on how topics created, still want kafka-node, going have exec command this:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 12 --topic <topic_name_here> 

i in node with:

const exec = require('child_process').exec;  function createtopic(topic, replfactor, numpartitions, cb) {   var zkhost = "localhost:2181";   var kafkahome = "/usr/local/kafka";    exec(     `${kafkahome}/bin/kafka-topics.sh --create --zookeeper ${zkhost} -- replication-factor ${replfactor} --partitions ${numpartitions} --topic ${topic}`,     (error,stderr,stdout) => cb(topic)   ); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -