Vorlage für das Verschicken von Nachrichten aus einer geteilten Lib spring/spring-producer--json--messages--vorlage spring/spring-producer--json--messages--vorlage--2025-03-signal spring/spring-producer--json--messages--vorlage--2025-04-signal
authorKai Moritz <kai@juplo.de>
Sun, 2 Feb 2025 17:46:32 +0000 (18:46 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 25 Mar 2025 18:57:45 +0000 (19:57 +0100)
README.sh [deleted file]
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
src/main/java/de/juplo/kafka/ExampleProducer.java
src/main/resources/application.yml

diff --git a/README.sh b/README.sh
deleted file mode 100755 (executable)
index 1780755..0000000
--- a/README.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/bash
-
-IMAGE=juplo/spring-producer:1.0-json-messages-SNAPSHOT
-
-if [ "$1" = "cleanup" ]
-then
-  docker compose -f docker/docker-compose.yml down -t0 -v --remove-orphans
-  mvn clean
-  exit
-fi
-
-docker compose -f docker/docker-compose.yml up -d --remove-orphans kafka-1 kafka-2 kafka-3
-docker compose -f docker/docker-compose.yml rm -svf producer
-
-if [[
-  $(docker image ls -q $IMAGE) == "" ||
-  "$1" = "build"
-]]
-then
-  mvn clean install || exit
-else
-  echo "Using image existing images:"
-  docker image ls $IMAGE
-fi
-
-docker compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1
-
-
-docker compose -f docker/docker-compose.yml up -d producer
-docker compose -f docker/docker-compose.yml up -d peter ute
-sleep 15
-
-docker compose -f docker/docker-compose.yml stop producer
-
-echo
-echo "Von peter empfangen:"
-docker compose -f docker/docker-compose.yml logs peter | grep '\ test\/.'
-echo
-echo "Von ute empfangen:"
-docker compose -f docker/docker-compose.yml logs ute | grep '\ test\/.'
-
-docker compose -f docker/docker-compose.yml stop peter ute
index b2c5cfa..efdfafa 100644 (file)
@@ -1,6 +1,5 @@
 package de.juplo.kafka;
 
-import de.juplo.messages.Message;
 import org.apache.kafka.clients.producer.Producer;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -20,7 +19,7 @@ public class ApplicationConfiguration
   public ExampleProducer exampleProducer(
     @Value("${spring.kafka.client-id}") String clientId,
     ApplicationProperties properties,
-    Producer<String, Message> kafkaProducer,
+    Producer<String, String> kafkaProducer,
     ConfigurableApplicationContext applicationContext)
   {
     return
index 2607dc0..8fb5ee6 100644 (file)
@@ -16,7 +16,7 @@ public class ExampleProducer implements Runnable
   private final String id;
   private final String topic;
   private final Duration throttle;
-  private final Producer<String, Message> producer;
+  private final Producer<String, String> producer;
   private final Thread workerThread;
   private final Runnable closeCallback;
 
@@ -28,7 +28,7 @@ public class ExampleProducer implements Runnable
     String id,
     String topic,
     Duration throttle,
-    Producer<String, Message> producer,
+    Producer<String, String> producer,
     Runnable closeCallback)
   {
     this.id = id;
@@ -90,10 +90,10 @@ public class ExampleProducer implements Runnable
   {
     final long time = System.currentTimeMillis();
 
-    final ProducerRecord<String, Message> record = new ProducerRecord<>(
+    final ProducerRecord<String, String> record = new ProducerRecord<>(
       topic,  // Topic
       key,    // Key
-      value   // Value
+      value.toString() // Value
     );
 
     producer.send(record, (metadata, e) ->
index 99e6508..008742c 100644 (file)
@@ -11,7 +11,6 @@ spring:
       buffer-memory: 33554432
       batch-size: 16384
       compression-type: gzip
-      value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
       properties:
         delivery-timeout: 10s
         max-block: 5s