I have made a custom Partitioner class that extends default Partitioner.
Problem : I want to add this custom Partitioner in KafkaSender.send method()
KafkaSender.send method() code :
sender.send(Flux.just(SenderRecord.create(new ProducerRecord<>(topic, partition, key, record, recordHeaders), 1))))
The partitioner here is an integer
Custom Partitioner Code:
public class CustomPartitioner extends DefaultPartitioner {
private final static String CHAR_FORMAT = "UTF-8";
@Override
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
// my logic
try {
return super.partition(topic, key, iocKey.toString().getBytes(CHAR_FORMAT), value, valueBytes, cluster);
} catch (UnsupportedEncodingException e) {
//error message
}
}
}
Note : I tried to hard code it using this below code
Properties properties = new Properties();
properties.put("partitioner.class", "CustomPartitioner ");
How can we force KafkaSender.send method() to use our custom partitioner?