From: Kai Moritz Date: Sun, 10 Nov 2024 16:19:53 +0000 (+0100) Subject: Version des ``spring-producer``, die ``long``-Werte verschickt X-Git-Tag: producer/spring-producer--long--2025-03-signal X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=da0d98193a31fff7a06f0987f2cff7c34f3d3f61;p=demos%2Fkafka%2Ftraining Version des ``spring-producer``, die ``long``-Werte verschickt --- diff --git a/README.sh b/README.sh index c8a0b221..67ea04b8 100755 --- 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 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 00f68fcc..4322ddf2 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -136,7 +136,7 @@ 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 @@ -147,12 +147,18 @@ services: command: kafka:9092 test my-group 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 + juplo.consumer.topic: test 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 + juplo.consumer.topic: test volumes: zookeeper-data: diff --git a/pom.xml b/pom.xml index f64266b4..96682900 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ spring-producer Spring Producer A Simple Producer, based on Spring Boot, that sends messages via Kafka - 1.0-SNAPSHOT + 1.0-long-SNAPSHOT 21 diff --git a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java index feb27a40..a9d081aa 100644 --- a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java @@ -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; @@ -20,8 +21,8 @@ public class ApplicationConfiguration public ExampleProducer exampleProducer( ApplicationProperties properties, KeyGenerator keyGenerator, - ValueGenerator valueGenerator, - Producer kafkaProducer, + ValueGenerator valueGenerator, + Producer kafkaProducer, ConfigurableApplicationContext applicationContext) { return @@ -44,13 +45,13 @@ public class ApplicationConfiguration } @Bean - ValueGenerator messageGenerator() + ValueGenerator messageGenerator() { - return i -> Long.toString(i); + return i -> i; } @Bean(destroyMethod = "") - public KafkaProducer kafkaProducer(ApplicationProperties properties) + public KafkaProducer kafkaProducer(ApplicationProperties properties) { Properties props = new Properties(); props.put("bootstrap.servers", properties.getBootstrapServer()); @@ -65,7 +66,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); }