From ae2532b066854504e39d84d9eeea73d9a936a708 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 2 Feb 2025 18:46:32 +0100 Subject: [PATCH] =?utf8?q?Vorlage=20f=C3=BCr=20das=20Verschicken=20von=20N?= =?utf8?q?achrichten=20aus=20einer=20geteilten=20Lib?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.sh | 42 ------------------- .../juplo/kafka/ApplicationConfiguration.java | 3 +- .../java/de/juplo/kafka/ExampleProducer.java | 8 ++-- src/main/resources/application.yml | 1 - 4 files changed, 5 insertions(+), 49 deletions(-) delete mode 100755 README.sh diff --git a/README.sh b/README.sh deleted file mode 100755 index 1780755a..00000000 --- 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 diff --git a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java index b2c5cfa7..efdfafa1 100644 --- a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java @@ -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 kafkaProducer, + Producer kafkaProducer, ConfigurableApplicationContext applicationContext) { return diff --git a/src/main/java/de/juplo/kafka/ExampleProducer.java b/src/main/java/de/juplo/kafka/ExampleProducer.java index 2607dc07..8fb5ee62 100644 --- a/src/main/java/de/juplo/kafka/ExampleProducer.java +++ b/src/main/java/de/juplo/kafka/ExampleProducer.java @@ -16,7 +16,7 @@ public class ExampleProducer implements Runnable private final String id; private final String topic; private final Duration throttle; - private final Producer producer; + private final Producer 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 producer, + Producer producer, Runnable closeCallback) { this.id = id; @@ -90,10 +90,10 @@ public class ExampleProducer implements Runnable { final long time = System.currentTimeMillis(); - final ProducerRecord record = new ProducerRecord<>( + final ProducerRecord record = new ProducerRecord<>( topic, // Topic key, // Key - value // Value + value.toString() // Value ); producer.send(record, (metadata, e) -> diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 99e65089..008742c1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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 -- 2.20.1