Created
June 4, 2021 21:04
-
-
Save kykl/58a98bf14bf7d73c228357715c46f56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def klog[T](topic: String, key: String, value: T): Unit = { | |
val props = new Properties() | |
import org.apache.kafka.clients.producer.ProducerConfig | |
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer") | |
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999") | |
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer") | |
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.protobuf.KafkaProtobufSerializer") | |
props.put("schema.registry.url", "http://127.0.0.1:8081") | |
val producer = new KafkaProducer[String, T](props) | |
val record = new ProducerRecord[String, T](topic, key, value) | |
producer.send(record) | |
producer.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment