Vorlage spring/supersimple-producer--vorlage---2023-06-signal
authorKai Moritz <kai@juplo.de>
Sat, 12 Nov 2022 11:35:27 +0000 (12:35 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 14 Jun 2023 23:15:40 +0000 (01:15 +0200)
src/main/java/de/juplo/kafka/Application.java

index 240f7d0..f6d6181 100644 (file)
@@ -7,11 +7,8 @@ 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 org.springframework.util.concurrent.ListenableFuture;
 
 
-// tag::supersimple[]
 @Slf4j
 @SpringBootApplication
 public class Application implements ApplicationRunner
@@ -24,21 +21,7 @@ public class Application implements ApplicationRunner
   {
     for (int i = 0; i < 100; i++)
     {
-      // end::supersimple[]
-      // tag::callback[]
-      ListenableFuture<SendResult<String, String>> listenableFuture =
-          kafkaTemplate.send("test", Long.toString(i%10), Long.toString(i));
-
-      listenableFuture.addCallback(
-          result -> log.info(
-              "Sent {}={} to partition={}, offset={}",
-              result.getProducerRecord().key(),
-              result.getProducerRecord().value(),
-              result.getRecordMetadata().partition(),
-              result.getRecordMetadata().offset()),
-          e -> log.error("ERROR sendig message", e));
-      // end::callback[]
-      // tag::supersimple[]
+      kafkaTemplate.send("test", Long.toString(i%10), Long.toString(i));
     }
   }
 
@@ -47,4 +30,3 @@ public class Application implements ApplicationRunner
     SpringApplication.run(Application.class, args);
   }
 }
-// end::supersimple[]