Vorlage spring-consumer--json--vorlage--2023-02-signal spring-consumer--json--vorlage-DEPRECATED
authorKai Moritz <kai@juplo.de>
Sun, 13 Nov 2022 21:14:00 +0000 (22:14 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 31 Jan 2023 16:55:23 +0000 (17:55 +0100)
README.sh
docker-compose.yml
pom.xml
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
src/main/java/de/juplo/kafka/SimpleConsumer.java
src/main/resources/application.yml

index e61188f..4f4e3ea 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -10,7 +10,6 @@ then
 fi
 
 docker-compose up -d kafka-1 kafka-2 kafka-3 cli
-docker-compose rm -svf consumer-1 consumer-2
 
 if [[
   $(docker image ls -q $IMAGE) == "" ||
@@ -23,26 +22,12 @@ else
   docker image ls $IMAGE
 fi
 
-docker-compose up -d
-docker-compose logs -f setup
+docker-compose up setup
+docker-compose ps
+docker-compose up -d producer
 
 while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer..."; sleep 1; done
-while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-1..."; sleep 1; done
-while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-2..."; sleep 1; done
 
-# tag::nachrichten[]
-echo 6  | http -v :8080/peter
-echo 77 | http -v :8080/klaus
-# end::nachrichten[]
+echo -n 3 | http -v :8080/foo;
 
-echo "Writing poison pill..."
-# tag::poisonpill[]
-echo 'BOOM!' | kafkacat -P -b :9092 -t test
-# end::poisonpill[]
-
-docker-compose logs -f consumer-1 consumer-2
-
-echo "Restarting consumer-1..."
-# tag::restart[]
-docker-compose up consumer-1
-# end::restart[]
+kafkacat -b :9092 -t test -o 0 -e -f 'p=%p|o=%o|k=%k|h=%h|v=%s\n'
index 7324b30..b47f679 100644 (file)
@@ -132,25 +132,3 @@ services:
       producer.bootstrap-server: kafka:9092
       producer.client-id: producer
       producer.topic: test
-
-  consumer-1:
-    image: juplo/spring-consumer-json:1.0-SNAPSHOT
-    ports:
-      - 8081:8080
-    environment:
-      server.port: 8080
-      spring.kafka.bootstrap-servers: kafka:9092
-      spring.kafka.client-id: consumer-1
-      spring.kafka.consumer.group-id: my-group
-      simple.consumer.topic: test
-
-  consumer-2:
-    image: juplo/spring-consumer-json:1.0-SNAPSHOT
-    ports:
-      - 8082:8080
-    environment:
-      server.port: 8080
-      spring.kafka.bootstrap-servers: kafka:9092
-      spring.kafka.client-id: consumer-2
-      spring.kafka.consumer.group-id: my-group
-      simple.consumer.topic: test
diff --git a/pom.xml b/pom.xml
index 1165685..e474870 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 
   <build>
     <plugins>
-      <plugin>
-        <groupId>pl.project13.maven</groupId>
-        <artifactId>git-commit-id-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
index a8b3e1d..62d61a2 100644 (file)
@@ -15,7 +15,7 @@ public class ApplicationConfiguration
 {
   @Bean
   public SimpleConsumer simpleConsumer(
-      Consumer<String, Message> kafkaConsumer,
+      Consumer<String, String> kafkaConsumer,
       KafkaProperties kafkaProperties,
       ApplicationProperties applicationProperties)
   {
index 45f9b94..8e557c2 100644 (file)
@@ -18,7 +18,7 @@ public class SimpleConsumer implements Callable<Integer>
 {
   private final String id;
   private final String topic;
-  private final Consumer<String, Message> consumer;
+  private final Consumer<String, String> consumer;
 
   private long consumed = 0;
 
@@ -33,11 +33,11 @@ public class SimpleConsumer implements Callable<Integer>
 
       while (true)
       {
-        ConsumerRecords<String, Message> records =
+        ConsumerRecords<String, String> records =
             consumer.poll(Duration.ofSeconds(1));
 
         log.info("{} - Received {} messages", id, records.count());
-        for (ConsumerRecord<String, Message> record : records)
+        for (ConsumerRecord<String, String> record : records)
         {
           handleRecord(
             record.topic(),
index 07d0625..c62240e 100644 (file)
@@ -30,13 +30,11 @@ spring:
       auto-offset-reset: earliest
       auto-commit-interval: 5s
       key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
-      value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
       properties:
         partition.assignment.strategy: org.apache.kafka.clients.consumer.StickyAssignor
         metadata.max.age.ms: 1000
-        spring.json.type.mapping: >
-          ADD:de.juplo.kafka.MessageAddNumber,
-          CALC:de.juplo.kafka.MessageCalculateSum
+        spring.json.type.mapping: TODO
 logging:
   level:
     root: INFO