Please demo this example, and do the lab together with students, step by step
Enable compression on Producer
None
15 mins
IF you haven't done before, let's create a testc
topic
$ ~/apps/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 \
--create --topic testc --replication-factor 1 --partitions 2
In a terminal
$ ~/apps/kafka/bin/kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--property print.key=true --property key.separator=":" \
--topic testc
or if you have Kafkacat
$ kafkacat -q -C -b localhost:9092 -t testc -f 'Partition %t[%p], offset: %o, key: %k, value: %s\n'
- Inspect file :
src/main/java/x/lab04_benchmark/CompressionProducer.java
. - Fix TODO items
- Run the Producer
In Eclipse,
- Right click on 'src/main/java/x/lab04_benchmark/CompressionProducer.java'
- Run as 'Java Application'
In Eclipse console, you should see output as follows:
sending : ProducerRecord(topic=test, partition=null, key=1, value=Hello world, timestamp=null)
The messages should show up in Kafka console terminal !
Yay !!
We can see transparent compression from Producer --> Consumer