Vorlage für die `KafkaTemplate`-Übung spring/supersimple-producer--vorlage spring/supersimple-producer--vorlage--2024-11-13--si
authorKai Moritz <kai@juplo.de>
Tue, 12 Nov 2024 18:01:01 +0000 (19:01 +0100)
committerKai Moritz <kai@juplo.de>
Thu, 14 Nov 2024 18:53:28 +0000 (19:53 +0100)
README.sh [deleted file]
src/main/java/de/juplo/kafka/ExampleProducer.java

diff --git a/README.sh b/README.sh
deleted file mode 100755 (executable)
index 929b422..0000000
--- a/README.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/bash
-
-IMAGE=juplo/supersimple-producer:1.0-SNAPSHOT
-
-if [ "$1" = "cleanup" ]
-then
-  docker compose -f docker/docker-compose.yml down -t0 -v --remove-orphans
-  mvn clean
-  exit
-fi
-
-docker compose -f docker/docker-compose.yml up -d --remove-orphans kafka-1 kafka-2 kafka-3
-docker compose -f docker/docker-compose.yml rm -svf producer
-
-if [[
-  $(docker image ls -q $IMAGE) == "" ||
-  "$1" = "build"
-]]
-then
-  mvn clean install || exit
-else
-  echo "Using image existing images:"
-  docker image ls $IMAGE
-fi
-
-docker compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1
-
-
-docker compose -f docker/docker-compose.yml up -d producer
-docker compose -f docker/docker-compose.yml up -d consumer-1 consumer-2
-sleep 15
-
-docker compose -f docker/docker-compose.yml stop producer
-
-echo
-echo "Von consumer-1 empfangen:"
-docker compose -f docker/docker-compose.yml logs consumer-1 | grep '\ test\/.'
-echo
-echo "Von consumer-2 empfangen:"
-docker compose -f docker/docker-compose.yml logs consumer-2 | grep '\ test\/.'
-
-docker compose -f docker/docker-compose.yml stop consumer-1 consumer-2
index 300d11e..36dc414 100644 (file)
@@ -1,19 +1,13 @@
 package de.juplo.kafka;
 
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.kafka.core.KafkaTemplate;
-import org.springframework.kafka.support.SendResult;
 
-import java.util.concurrent.CompletableFuture;
 
-
-@Slf4j
-// tag::supersimple[]
 @SpringBootApplication
 public class ExampleProducer implements ApplicationRunner
 {
@@ -25,27 +19,7 @@ public class ExampleProducer implements ApplicationRunner
   {
     for (int i = 0; true; i++)
     {
-      // end::supersimple[]
-      // tag::callback[]
-      CompletableFuture<SendResult<String, String>> completableFuture =
-      // tag::supersimple[]
-          kafkaTemplate.sendDefault(Long.toString(i%10), Long.toString(i));
-      // end::supersimple[]
-
-      completableFuture.thenAccept(result ->
-        log.info(
-          "Sent {}={} to partition={}, offset={}",
-          result.getProducerRecord().key(),
-          result.getProducerRecord().value(),
-          result.getRecordMetadata().partition(),
-          result.getRecordMetadata().offset()));
-
-      completableFuture.exceptionally(e -> {
-        log.error("ERROR sendig message", e);
-        return null;
-      });
-      // end::callback[]
-      // tag::supersimple[]
+      kafkaTemplate.sendDefault(Long.toString(i%10), Long.toString(i));
     }
   }
 
@@ -54,4 +28,3 @@ public class ExampleProducer implements ApplicationRunner
     SpringApplication.run(ExampleProducer.class, args);
   }
 }
-// end::supersimple[]