From de96d1324ba4c69789ae1aeab4bf72ad49e2ae8a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 19 Nov 2022 16:53:37 +0100 Subject: [PATCH] =?utf8?q?=C3=9Cber=20`=3Ferror=3D1`=20kann=20ein=20Fehler?= =?utf8?q?=20den=20Nachrichtenstrom=20eingebettet=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.sh | 5 +++-- src/main/java/de/juplo/kafka/RestProducer.java | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.sh b/README.sh index 0e8d4d3..ebea433 100755 --- a/README.sh +++ b/README.sh @@ -31,8 +31,9 @@ while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Wait docker-compose up -d peter klaus -sleep 10 -docker-compose kill -s9 peter klaus +sleep 5 +echo 17 | http -v :8080/foo?error=1 +docker-compose stop peter klaus # tag::kafkacat[] kafkacat -b :9092 -t test -o 0 -e -f 'p=%p|o=%o|k=%k|h=%h|v=%s\n' diff --git a/src/main/java/de/juplo/kafka/RestProducer.java b/src/main/java/de/juplo/kafka/RestProducer.java index 4be2dcd..53064f1 100644 --- a/src/main/java/de/juplo/kafka/RestProducer.java +++ b/src/main/java/de/juplo/kafka/RestProducer.java @@ -28,13 +28,15 @@ public class RestProducer public DeferredResult send( @PathVariable String key, @RequestHeader(name = "X-id", required = false) Long correlationId, - @RequestBody Integer number) + @RequestBody Integer number, + @RequestParam(required = false) boolean error) { ResultRecorder result = new ResultRecorder(number+1); for (int i = 1; i <= number; i++) { - send(key, new AddNumberMessage(number, i), correlationId, result); + int next = error && i == (number+1)/2 ? i * -1 : i; + send(key, new AddNumberMessage(number, next), correlationId, result); } send(key, new CalculateSumMessage(number), correlationId, result); -- 2.20.1