示例化kafkaproducer时获取异常

ca1c2owp  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(355)

我使用的是kafka代理的ibmbluemix实现。
我正在创建具有以下属性的kafkaproducer:

key.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
bootstrap.servers=xxxx.xxxxxx.xxxxxx.xxxxxx.bluemix.net:xxxx
client.id=messagehub
acks=-1
security.protocol=SASL_SSL
ssl.protocol=TLSv1.2
ssl.enabled.protocols=TLSv1.2
ssl.truststore.location=xxxxxxxxxxxxxxxxx
ssl.truststore.password=xxxxxxxx
ssl.truststore.type=JKS
ssl.endpoint.identification.algorithm=HTTPS

KafkaProducer<byte[], byte[]> kafkaProducer = 
           new KafkaProducer<byte[], byte[]>(props);

我有以下例外:
org.apache.kafka.common.kafkaexception:org.apache.kafka.clients.producer.internals.defaultpartitioner不是org.apache.kafka.clients.producer.partitioner的示例
读完以下博客:http://blog.rocana.com/kafkas-defaultpartitioner-and-byte-arrays 我在属性文件中添加了以下行,尽管我正在使用新的api:

partitioner.class=kafka.producer.ByteArrayPartitioner

现在我得到一个例外:
org.apache.kafka.common.kafkaexception:无法示例化类kafka.producer.bytearraypartitioner它是否具有公共的无参数构造函数?
看起来像 ByteArrayPartitioner 没有默认构造函数。你知道我在这里遗漏了什么吗?
谢谢你,马杜

wnavrhmk

wnavrhmk1#

当我使用kafkaproducerapi时,我不需要

partitioner.class=kafka.producer.ByteArrayPartitioner

财产。问题是Kafka客户端jar有两个副本。我们已经将安装配置为所有库jar文件都位于外部共享目录中。但是由于pom配置错误,war文件的lib目录中还有一个kafka客户机的副本。一旦我解决了这个问题,它工作得很好。
马杜

相关问题