-1

我正在使用 Kafka Broker 的 IBM Bluemix 实现。

我正在创建具有以下属性的 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没有默认构造函数。知道我在这里缺少什么吗?

谢谢马杜

4

1 回答 1

0

因为我使用的是 KafkaProducer API,所以我不需要

partitioner.class=kafka.producer.ByteArrayPartitioner 

财产。问题是有 2 个 kafkaclient jar 副本。我们已经配置了我们的安装,以便所有库 jar 文件都位于外部共享目录中。但是由于 POM 配置错误,war 文件的 lib 目录中也有 kafka 客户端的副本。一旦我解决了这个问题,它工作得很好。

马杜

于 2016-05-01T22:12:57.920 回答