Duration: 30 mins
Read the javadoc of KafkaProducer and ProducerConfig
Add the kafka-clients dependency to build.sbt, matching the broker
version from 01_kafka_docker.md
libraryDependencies += "org.apache.kafka" % "kafka-clients" % "4.3.1"
Use mvnrepository to know the proper entry for kafka-clients dependency.
KafkaProducer[String, String]Properties object and fill out the missing properties guided by exceptions at runtimeProperties object with bootstrap.servers,
key.serializer and value.serializer — use the ProducerConfig
constants, not raw string literalsProducerRecords to topic orders, with keys
order-0 .. order-9 and a value of your choosingclose() on the producer at the end so buffered records are
flushed before the JVM exitsRun it, then verify the records arrived with the console consumer from 02_topics_and_cli.md (recreate the orders topic first if you deleted it there)
build.sbtsrc/main/resources for whichever
binding you pickedclose() (or replace it
with System.exit(0) right after send)? Try it and watch the console
consumer — do all 10 records still arrive?