]> juplo.de Git - demos/kafka/training/commitdiff
Version des ``spring-producer``, die ``long``-Werte verschickt producer/spring-producer--long producer/spring-producer--long--2025-05-lvm producer/spring-producer--long--2025-05-lvm--spickzettel producer/spring-producer--long--2025-05-signal-spickzettel
authorKai Moritz <kai@juplo.de>
Sun, 10 Nov 2024 16:19:53 +0000 (17:19 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 7 May 2025 19:14:20 +0000 (21:14 +0200)
README.sh
docker/docker-compose.yml
pom.xml
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
src/main/java/de/juplo/kafka/ExampleProducer.java
src/main/resources/application.yml

index 77fc3743b87b9ad863e2a8dbb04746794f065de7..5e6270ac1c93aaf7d11a8f42430ed7bc04fe08f5 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-IMAGE=juplo/spring-producer:2.0-SNAPSHOT
+IMAGE=juplo/spring-producer:2.0-long-SNAPSHOT
 
 if [ "$1" = "cleanup" ]
 then
index 59e7ed5783c6cd61198af11e55ac83d32df204e5..0fbb8de5f64a866dbfb81bfa7073df2a512f7ad6 100644 (file)
@@ -136,23 +136,29 @@ services:
       - kafka-3
 
   producer:
-    image: juplo/spring-producer:2.0-SNAPSHOT
+    image: juplo/spring-producer:2.0-long-SNAPSHOT
     environment:
       spring.kafka.bootstrap-servers: kafka:9092
       spring.kafka.client-id: producer
       juplo.producer.topic: test
 
   consumer:
-    image: juplo/simple-consumer:1.0-SNAPSHOT
-    command: kafka:9092 test my-group consumer
+    image: juplo/spring-consumer:1.1-SNAPSHOT
+    environment:
+      juplo.bootstrap-server: kafka:9092
+      juplo.client-id: consumer
 
   peter:
-    image: juplo/simple-consumer:1.0-SNAPSHOT
-    command: kafka:9092 test my-group peter
+    image: juplo/spring-consumer:1.1-long-SNAPSHOT
+    environment:
+      juplo.bootstrap-server: kafka:9092
+      juplo.client-id: peter
 
   ute:
-    image: juplo/simple-consumer:1.0-SNAPSHOT
-    command: kafka:9092 test my-group ute
+    image: juplo/spring-consumer:1.1-long-SNAPSHOT
+    environment:
+      juplo.bootstrap-server: kafka:9092
+      juplo.client-id: ute
 
 volumes:
   zookeeper-data:
diff --git a/pom.xml b/pom.xml
index be7dea5d9fe51399235bb339d628904c08fb8241..a8b37b415962ddabf97a9a01ab5c35d1ba4f9ec1 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
   <artifactId>spring-producer</artifactId>
   <name>Spring Producer</name>
   <description>A Simple Producer, based on Spring Boot, that sends messages via Kafka</description>
-  <version>2.0-SNAPSHOT</version>
+  <version>2.0-long-SNAPSHOT</version>
 
   <properties>
     <java.version>21</java.version>
index efdfafa179d6e0c27c16cdeb15ea8d0e7666f506..c0bade1cbf6d5e8d8dab259956cfcc437cbbd71b 100644 (file)
@@ -19,7 +19,7 @@ public class ApplicationConfiguration
   public ExampleProducer exampleProducer(
     @Value("${spring.kafka.client-id}") String clientId,
     ApplicationProperties properties,
-    Producer<String, String> kafkaProducer,
+    Producer<String, Long> kafkaProducer,
     ConfigurableApplicationContext applicationContext)
   {
     return
index c5a5a80d2d2a1798ac0c59873c5bd9ec833db5c4..c0633b0434fe1e5d78ba009fcef1ae6e67ca4725 100644 (file)
@@ -13,7 +13,7 @@ public class ExampleProducer implements Runnable
   private final String id;
   private final String topic;
   private final Duration throttle;
-  private final Producer<String, String> producer;
+  private final Producer<String, Long> producer;
   private final Thread workerThread;
   private final Runnable closeCallback;
 
@@ -25,7 +25,7 @@ public class ExampleProducer implements Runnable
     String id,
     String topic,
     Duration throttle,
-    Producer<String, String> producer,
+    Producer<String, Long> producer,
     Runnable closeCallback)
   {
     this.id = id;
@@ -49,7 +49,7 @@ public class ExampleProducer implements Runnable
     {
       for (; running; i++)
       {
-        send(Long.toString(i%10), Long.toString(i));
+        send(Long.toString(i%10), i);
 
         if (throttle.isPositive())
         {
@@ -78,11 +78,11 @@ public class ExampleProducer implements Runnable
     }
   }
 
-  void send(String key, String value)
+  void send(String key, long value)
   {
     final long time = System.currentTimeMillis();
 
-    final ProducerRecord<String, String> record = new ProducerRecord<>(
+    final ProducerRecord<String, Long> record = new ProducerRecord<>(
       topic,  // Topic
       key,    // Key
       value   // Value
index 3f6c233a1751059d20f011c9b365a87000206669..d4ca69acc7fe7af8a8cba598ba37b561e98b66dd 100644 (file)
@@ -11,6 +11,7 @@ spring:
       buffer-memory: 33554432
       batch-size: 16384
       compression-type: gzip
+      value-serializer: org.apache.kafka.common.serialization.LongSerializer
       properties:
         metadata.max.age.ms: 5000
         request.timeout.ms: 5000