kafka-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 罗 辉 <luo...@zetyun.com>
Subject 答复: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
Date Thu, 06 Jul 2017 01:55:18 GMT
thanks you ,got this problem solved with your advice

________________________________
发件人: tao xiao <xiaotao183@gmail.com>
发送时间: 2017年7月5日 20:55:45
收件人: users@kafka.apache.org
主题: Re: org.apache.kafka.common.KafkaException: Failed to construct kafka producer

you need to use org.apache.kafka.common.serialization.StringSerializer as
your ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG

On Wed, 5 Jul 2017 at 19:18 罗 辉 <luohui@zetyun.com> wrote:

> hi guys:
>
>   I got an exception which i searched searchhadoop.com and the archive as
> well and got no matches, here it is:
>
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
> more info.
> Exception in thread "main" org.apache.kafka.common.KafkaException: Failed
> to construct kafka producer
>  at
> org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:342)
>  at
> org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:191)
>  at com.zetyum.www.P$.main(P.scala:28)
>  at com.zetyum.www.P.main(P.scala)
> Caused by: org.apache.kafka.common.KafkaException:
> org.apache.kafka.common.serialization.StringDeserializer is not an instance
> of org.apache.kafka.common.serialization.Serializer
>  at
> org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:205)
>  at
> org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:239)
>  ... 3 more
>
>
> add I tried 0.11 and 0.10 for scala 2.10, both got upper exception. Here
> is my code:
>
> import org.apache.kafka._
> import org.apache.kafka.clients._
> import org.apache.kafka.clients.producer._
> import org.apache.kafka.clients.consumer._
> import org.apache.kafka.common.serialization._
> import java.util.Properties
>
> object P {
>   def main(args: Array[String]) {
>     val brokers = "localhost:9092"
>     val topic = "test"
>     // Zookeeper connection properties
>     val props = new Properties()
>     props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers)
>     props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
>       "org.apache.kafka.common.serialization.StringDeserializer")
>     props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
>       "org.apache.kafka.common.serialization.StringSerializer")
>     val producer = new KafkaProducer[String, String](props)
>     while (true) {
>       val message = new ProducerRecord[String, String](topic, "1", "1")
>       println(message)
>       producer.send(message)
>     }
>     Thread.sleep(1000)
>   }
> }
>
> thanks for any advices
>
>
> San
>
>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message