2016-05-01 136 views
-1

我正在使用Kafka Broker的IBM Bluemix实现。实例化KafkaProducer时发生异常

我有以下属性创建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没有默认的构造函数。 有什么想法我在这里失踪?

感谢 马杜

回答

0

由于我用的是KafkaProducer API,我并不需要

partitioner.class=kafka.producer.ByteArrayPartitioner 

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

Madhu