apache-kafkaproducer-consumerkafka-producer-apiproducer

What does Broker do when multiple Producers write the same message to Broker? And one more related question (due to 150 character limit)


Producer A writes a message to Broker A (partition 1), and Producer B writes the same message to Broker A(partition 1). What happens to the message or the Broker?

I'm guessing since there is the same message, Producer B stops the same message, and continue with the next part of the message?

I have one more question If you want to send a movie file ,for example, to Kafka Cluster, can I make 4 producers and have them send different parts of that movie into the cluster? For instance, Producer A sends the first part of the movie, Producer B sends the second part of the movie, and so on. (Because that seems to work more efficiently than one producer.)


Solution

    1. If 2 producers send the same message to Kafka, the message is written twice. Kafka does not check the content of messages. It's the same if you were to call send() twice in a producer, you get 2 messages in Kafka.

    2. If you want to send large amounts of data, it's recommended to use multiple producers to split the work. Also Kafka is not really designed to handle >1GB messages so splitting large files into smaller chunks is a good idea. Just be careful how you split your data because you'll may have to reassemble it on the consumer side!