I am curious to know which partition the messages will be written, if we provide the message key as well as the partition. Will the message be posted based on the partition key or to the specific partition in Apache Kafka?
If you provide the partition
number in one of the constructor methods that allow you to supply the partition number in ProducerRecord
object, then the partition number will be used by default.
The key is only used if the partition number is NOT provided.
Here's a couple of references suggesting this:
Edit - added one more tutorial reference .