简体   繁体   中英

How to set custom Partitioner for kafka in Flink 1.14.3?

    val mySink = KafkaSink.builder()
  .setBootstrapServers(bootstrapserver)
  .setKafkaProducerConfig(myproperties)
  .setDeliverGuarantee(DeliveryGuarantee.AT_LEAST_ONCE)
      .setRecordSerializer(
        new mycustomSerializer(mytopic,
                schemaregistryurl)

      ).build()

class mycustomSerializer(topic: String, schemaRegistryUrl: String) extends 
KafkaRecordSerializationSchema[MyRecord]

Although the above code is working fine but i am unable to set the custom partitioner in above code

I have gone through the documentation if we make mycustomSerializer using KafkaRecorderSerializationSchema.builder() then we can set easily but how to do that in above code?

The serializer shouldn't set the partitioner.

Inside of myproperties map, you should be able to set ProducerConfig.PARTITIONER_CLASS_CONFIG key with the value of your custom class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM