]> juplo.de Git - demos/kafka/training/commitdiff
Der Producer schreibt gezielt in eine fixe (konfigurierbare) Partition producer/spring-producer--fixedsharding producer/spring-producer--fixedsharding--2026-03-22--22-01 producer/spring-producer--fixedsharding--2026-03-lvm
authorKai Moritz <kai@juplo.de>
Tue, 29 Oct 2024 15:48:54 +0000 (16:48 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 22 Mar 2026 20:02:43 +0000 (21:02 +0100)
README.sh
build.gradle
docker/docker-compose.yml
pom.xml
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
src/main/java/de/juplo/kafka/ApplicationProperties.java
src/main/java/de/juplo/kafka/ExampleProducer.java
src/main/resources/application.yml

index a6dff1ede2faa81235af0e8b9868c949399b9352..48aef64b47fcbde43a4621f233aacc1915ee4223 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-fixedsharding-SNAPSHOT
 
 if [ "$1" = "cleanup" ]
 then
index d237c1f5b066cf409887b32ed7398e3369023f3d..107da4d138a4912d8b7ac32847a3791f169d84db 100644 (file)
@@ -8,7 +8,7 @@ plugins {
 }
 
 group = 'de.juplo.kafka'
-version = '1.0-SNAPSHOT'
+version = '1.0-fixedsharding-SNAPSHOT'
 
 java {
        toolchain {
index a5a6b64f60a998f4e492a57f81ff8cfc9186a881..722122f95939797016146cc5ba79f2ab15e6a919 100644 (file)
@@ -173,11 +173,12 @@ services:
       - kafka-3
 
   producer:
-    image: juplo/spring-producer:1.0-SNAPSHOT
+    image: juplo/spring-producer:1.0-fixedsharding-SNAPSHOT
     environment:
       juplo.bootstrap-server: kafka:9092
       juplo.client-id: producer
       juplo.producer.topic: test
+      juplo.producer.partition: 0
     cpu_period: 100000
     cpu_quota:  50000
     mem_limit:  100m
diff --git a/pom.xml b/pom.xml
index 5de7233dd85bfc99b1e2f9258bd680fdc46c0fae..0060d4bc8c6bb3b6b17a0e15bba44fc8938e455b 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>1.0-SNAPSHOT</version>
+  <version>1.0-fixedsharding-SNAPSHOT</version>
 
   <properties>
     <java.version>21</java.version>
index 0090ceeab45f9b9e4a262dada2ef52a37744ba7a..ab4892561044a75d9eca2714d84858c49a18b1ab 100644 (file)
@@ -26,6 +26,7 @@ public class ApplicationConfiguration
       new ExampleProducer(
         properties.getClientId(),
         properties.getProducerProperties().getTopic(),
+        properties.getProducerProperties().getPartition(),
         properties.getProducerProperties().getThrottle() == null
           ? Duration.ofMillis(500)
           : properties.getProducerProperties().getThrottle(),
index 43232628755882f32117ac1a72c5ade16dd13f1e..65b71f3a542a2106022de48946027a263b3f38bc 100644 (file)
@@ -42,6 +42,8 @@ public class ApplicationProperties
     @NotEmpty
     private String topic;
     @NotNull
+    private Integer partition;
+    @NotNull
     @NotEmpty
     private String acks;
     @NotNull
index 93d0d1738a3ce0eeabb83cd040c01b41dac4bda9..acbe64f59f6c991bf7422a05cf04a6d892bec47d 100644 (file)
@@ -12,6 +12,7 @@ public class ExampleProducer implements Runnable
 {
   private final String id;
   private final String topic;
+  private final int partition;
   private final Duration throttle;
   private final Producer<String, String> producer;
   private final Thread workerThread;
@@ -24,12 +25,14 @@ public class ExampleProducer implements Runnable
   public ExampleProducer(
     String id,
     String topic,
+    int partition,
     Duration throttle,
     Producer<String, String> producer,
     Runnable closeCallback)
   {
     this.id = id;
     this.topic = topic;
+    this.partition = partition;
     this.throttle = throttle;
     this.producer = producer;
 
@@ -84,6 +87,7 @@ public class ExampleProducer implements Runnable
 
     final ProducerRecord<String, String> record = new ProducerRecord<>(
       topic,  // Topic
+      partition, // Partition
       key,    // Key
       value   // Value
     );
index 21fef284f03e091e3a9e7f87758e5fef9fb2fe42..332873fd5a7d02aaa59015c905a942425f53e830 100644 (file)
@@ -3,6 +3,7 @@ juplo:
   client-id: DEV
   producer:
     topic: test
+    partition: 0
     acks: -1
     delivery-timeout: 10s
     max-block: 5s
@@ -30,6 +31,7 @@ info:
     client-id: ${juplo.client-id}
     producer:
       topic: ${juplo.producer.topic}
+      partition: ${juplo.producer.partition}
       acks: ${juplo.producer.acks}
       delivery-timeout: ${juplo.producer.delivery-timeout}
       max-block: ${juplo.producer.max-block}