From: Kai Moritz Date: Sat, 19 Nov 2022 15:53:37 +0000 (+0100) Subject: Über `?error=1` kann ein Fehler den Nachrichtenstrom eingebettet werden X-Git-Tag: rest-producer--json--fehlerteufel X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=de96d1324ba4c69789ae1aeab4bf72ad49e2ae8a;p=demos%2Fkafka%2Ftraining Über `?error=1` kann ein Fehler den Nachrichtenstrom eingebettet werden --- 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);