I have a usecase where the incoming data has a key that identifies different type of the data. There's a single input kafka topic where all types of data are thrown at it. The beam pipeline reads all the messages from the input kafka topic and has to route to different kafka topics depending on the key.
As present, KafkaIO doesn't support writing to multiple topics using a single producer. The following code is inner working code of the KafkaIO.write()
final class AutoValue_KafkaIO_Write<K, V> extends Write<K, V> {
private final String topic;
private final WriteRecords<K, V> writeRecordsTransform;
private AutoValue_KafkaIO_Write(@Nullable String topic, WriteRecords<K, V> writeRecordsTransform) {
this.topic = topic;
this.writeRecordsTransform = writeRecordsTransform;
}
How to do it using kafkaIO producer of apache beam?