From: Kai Moritz Date: Mon, 5 Dec 2022 19:35:50 +0000 (+0100) Subject: Vorlage & Setup für Fire-n-Forget-Übung überarbeitet X-Git-Tag: simple-producer--fire+forget--DEPRICATED X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f0f6d117020ce7600e2f240c74952e22c6abe0a1;p=demos%2Fkafka%2Ftraining Vorlage & Setup für Fire-n-Forget-Übung überarbeitet --- diff --git a/README.sh b/README.sh index 2c57e05..65479e3 100755 --- a/README.sh +++ b/README.sh @@ -1,6 +1,6 @@ #!/bin/bash -IMAGE=juplo/simple-producer:1.0-SNAPSHOT +IMAGE=juplo/fire-forget:1.0-SNAPSHOT if [ "$1" = "cleanup" ] then @@ -25,11 +25,6 @@ fi docker-compose up setup docker-compose ps -docker-compose up -d producer -sleep 5 +docker-compose up producer -docker-compose exec cli kafkacat -b kafka:9092 -t test -c 20 -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n' - -docker-compose stop producer -docker-compose exec cli kafkacat -b kafka:9092 -t test -e -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n' -docker-compose logs producer +kafkacat -b :9092 -e -q -t test | wc -l diff --git a/docker-compose.yml b/docker-compose.yml index 3ff7c27..83b90a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -107,5 +107,5 @@ services: - kafka-3 producer: - image: juplo/simple-producer:1.0-SNAPSHOT + image: juplo/fire-forget:1.0-SNAPSHOT command: kafka:9092 test producer diff --git a/pom.xml b/pom.xml index 4c52f37..c61969c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ de.juplo.kafka - simple-producer + fire-forget Super Simple Producer 1.0-SNAPSHOT diff --git a/src/main/java/de/juplo/kafka/SimpleProducer.java b/src/main/java/de/juplo/kafka/SimpleProducer.java index 9fcaa6e..2bab38d 100644 --- a/src/main/java/de/juplo/kafka/SimpleProducer.java +++ b/src/main/java/de/juplo/kafka/SimpleProducer.java @@ -16,8 +16,6 @@ public class SimpleProducer private final KafkaProducer producer; private long produced = 0; - private volatile boolean running = true; - private volatile boolean done = false; public SimpleProducer(String broker, String topic, String clientId) { @@ -35,23 +33,16 @@ public class SimpleProducer public void run() { - long i = 0; - try { - for (; running ; i++) + for (int i = 0; i < 10000 ; i++) { send(Long.toString(i%10), Long.toString(i)); - Thread.sleep(500); } } - catch (InterruptedException e) {} finally { - log.info("{}: Closing the KafkaProducer", id); - producer.close(); log.info("{}: Produced {} messages in total, exiting!", id, produced); - done = true; } } @@ -126,21 +117,6 @@ public class SimpleProducer SimpleProducer instance = new SimpleProducer(broker, topic, clientId); - Runtime.getRuntime().addShutdownHook(new Thread(() -> - { - instance.running = false; - while (!instance.done) - { - log.info("Waiting for main-thread..."); - try - { - Thread.sleep(1000); - } - catch (InterruptedException e) {} - } - log.info("Shutdown completed."); - })); - log.info( "Running SimpleProducer: broker={}, topic={}, client-id={}", broker,