TaoZex commented on code in PR #3085:
URL:
https://github.com/apache/incubator-seatunnel/pull/3085#discussion_r995556541
##########
seatunnel-connectors-v2/connector-kafka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/sink/KafkaSinkWriter.java:
##########
@@ -63,7 +66,28 @@ public class KafkaSinkWriter implements
SinkWriter<SeaTunnelRow, KafkaCommitInfo
// check config
@Override
public void write(SeaTunnelRow element) {
- ProducerRecord<byte[], byte[]> producerRecord =
seaTunnelRowSerializer.serializeRow(element);
+ ProducerRecord<byte[], byte[]> producerRecord = null;
+ //Determine the partition of the kafka send message based on the field
name
+ if (pluginConfig.hasPath(PARTITION_KEY)){
+ String keyField = pluginConfig.getString(PARTITION_KEY);
+ List<String> fields =
Arrays.asList(seaTunnelRowType.getFieldNames());
+ String key;
+ if (fields.contains(keyField)) {
+ Object field = element.getField(fields.indexOf(keyField));
+ //If the field is null, send the message to the same partition
+ if (field == null) {
+ key = "null";
Review Comment:
It' s a good way, thanks for your advice.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]