Developing Kafka Application With Producer API

Exercise

@jaceklaskowski / StackOverflow / GitHub / LinkedIn
The "Internals" Books: Apache KafkaKafka Streams

Sample Application


            val props = new Properties()
            props.put(
              ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
              classOf[StringSerializer].getName)
            props.put(
              ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
              classOf[StringSerializer].getName)
            props.put(
              ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
              "localhost:9092,localhost:9192,localhost:9292")
            val producer = new KafkaProducer[String, String](props)
            val r = new ProducerRecord[String, String]("demo", 1, "1", "hello 1s")
            producer.send(r)
            producer.close()