Can't send a keyedMessage to brokers with part

2019-09-04 11:38发布

I have a 2 nodes kafka cluster with 2 instances of brokers and zookeepers. And then I create a topic kafka-test with 2 partitions and replication-factor =2. My producer config is: {"partitioner.class" "kafka.producer.DefaultPartitioner" "metadata.broker.list" "172.32.1.248:9092,172.32.1.251:9092" "request.required.acks" "1"}

So for the DefaultPartitoner, it will calculate and hashvalue and divide by the num_partiton to decide which partition the data it will go, so I create my keyedMessage val key-msg = KeyedMessage("kafka-test","a","test message!") prod.send(key-msg)

"a"'s hashValue is 97 and 97 % 2 = 1, so the data should go to partition1. However, the data did't get send to the brokers (I have a console consumer running that didn't receive any message from this topic). If I create the key-msg without the key, it works fine

val key-msg = KeyedMessage("kafka-test","test message!") prod.send(key-msg)

Am I using the key wrong or anything? Thanks

0条回答
登录 后发表回答