]> juplo.de Git - demos/kafka/training/commitdiff
Version des ``spring-producer``, die ``long``-Werte verschickt springkafka/spring-producer--long springkafka/spring-producer--long--2026-03-22--22-01 springkafka/spring-producer--long--2026-03-lvm
authorKai Moritz <kai@juplo.de>
Sun, 10 Nov 2024 16:19:53 +0000 (17:19 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 22 Mar 2026 20:54:19 +0000 (21:54 +0100)
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 1d208d534a05f579cb7a49e78aecf53c9699b79c..2325c2226d5d6323dbc041181b1691b7419cf566 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 d151dab5dd111e95b65cfc4d4c92b380e45ea14b..e7218d0f91e3b61a370175b211d4defef495a619 100644 (file)
@@ -173,23 +173,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:
   controller-data:
diff --git a/pom.xml b/pom.xml
index 77011f97d373b55bfa4643fc25a3d30988f4b0e6..137a8eaaf2b2de15b8321d1c998723bc0f39b1a0 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 93d0d1738a3ce0eeabb83cd040c01b41dac4bda9..d49deb6bfde993a57fd52e6276a671bfa354b065 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 sendRequested = 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