简体   繁体   中英

Kafka Producer producer.send very slow

I'm trying to write a simple Avro message producer for Kafka, using Scala.

The problem I am having is that the sending is very slow.

I am doing this:

val message: GenericRecord = getRandomMessage()
val serializedMessage: Array[Byte] = serializeMessage(message)

val queueMessage = new ProducerRecord[String, Array[Byte]](topic, message.get("id").toString, serializedMessage)
producer.send(queueMessage)
println("Sent Message: "+ message)

Both when deploying to my cluster, as well as when running from my IDE it is extremely slow to send the messages.

From what I read the message should be asynchronous and quicker than this.

Is there something obvious that I'm missing?

Thanks!

Are you sure that the message has been sent?

It seems that the send failed (or ran in a timeout) and then you print the message, which is not a guarantee of a successful sending of course.

To verify this, try to wait on the send and print the result:

println(producer.send(queueMessage).get)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM