Version des ``spring-producer``, die ``long``-Werte verschickt consumer/spring-producer--long consumer/spring-producer--long--2024-11-13--si
authorKai Moritz <kai@juplo.de>
Sun, 10 Nov 2024 16:19:53 +0000 (17:19 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 10 Nov 2024 16:19:53 +0000 (17:19 +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

index 499780a..cb10b58 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-IMAGE=juplo/spring-producer:1.0-SNAPSHOT
+IMAGE=juplo/spring-producer:1.0-long-SNAPSHOT
 
 if [ "$1" = "cleanup" ]
 then
index c417a7f..b899570 100644 (file)
@@ -190,19 +190,25 @@ services:
       - kafka-3
 
   producer:
-    image: juplo/spring-producer:1.0-SNAPSHOT
+    image: juplo/spring-producer:1.0-long-SNAPSHOT
     environment:
       juplo.bootstrap-server: kafka:9092
       juplo.client-id: producer
       juplo.producer.topic: test
 
   consumer-1:
-    image: juplo/simple-consumer:1.0-SNAPSHOT
-    command: kafka:9092 test my-group consumer-1
+    image: juplo/spring-consumer:1.1-long-SNAPSHOT
+    environment:
+      juplo.bootstrap-server: kafka:9092
+      juplo.client-id: consumer-1
+      juplo.consumer.topic: test
 
   consumer-2:
-    image: juplo/simple-consumer:1.0-SNAPSHOT
-    command: kafka:9092 test my-group consumer-2
+    image: juplo/spring-consumer:1.1-long-SNAPSHOT
+    environment:
+      juplo.bootstrap-server: kafka:9092
+      juplo.client-id: consumer-2
+      juplo.consumer.topic: test
 
 volumes:
   zookeeper-data:
diff --git a/pom.xml b/pom.xml
index 841299b..78c74ec 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
   <artifactId>spring-producer</artifactId>
   <name>Spring Producer</name>
   <description>A Simple Spring-Boot-Producer, that takes messages via POST and confirms successs</description>
-  <version>1.0-SNAPSHOT</version>
+  <version>1.0-long-SNAPSHOT</version>
 
   <properties>
     <java.version>21</java.version>
index 7540dd3..d8e9554 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka;
 
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.common.serialization.LongSerializer;
 import org.apache.kafka.common.serialization.StringSerializer;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.ConfigurableApplicationContext;
@@ -19,7 +20,7 @@ public class ApplicationConfiguration
   @Bean
   public ExampleProducer exampleProducer(
       ApplicationProperties properties,
-      Producer<String, String> kafkaProducer,
+      Producer<String, Long> kafkaProducer,
       ConfigurableApplicationContext applicationContext)
   {
     return
@@ -34,7 +35,7 @@ public class ApplicationConfiguration
   }
 
   @Bean(destroyMethod = "")
-  public KafkaProducer<String, String> kafkaProducer(ApplicationProperties properties)
+  public KafkaProducer<String, Long> kafkaProducer(ApplicationProperties properties)
   {
     Properties props = new Properties();
     props.put("bootstrap.servers", properties.getBootstrapServer());
@@ -49,7 +50,7 @@ public class ApplicationConfiguration
     props.put("linger.ms", properties.getProducerProperties().getLinger().toMillis());
     props.put("compression.type", properties.getProducerProperties().getCompressionType());
     props.put("key.serializer", StringSerializer.class.getName());
-    props.put("value.serializer", StringSerializer.class.getName());
+    props.put("value.serializer", LongSerializer.class.getName());
 
     return new KafkaProducer<>(props);
   }
index bc5cf89..7ac41bd 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