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-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ferrorhandling%2Frest-producer--json--fehlerteufel;p=demos%2Fkafka%2Ftraining Über `?error=1` kann ein Fehler den Nachrichtenstrom eingebettet werden --- diff --git a/README.sh b/README.sh index 427eca3..9ed2751 100755 --- a/README.sh +++ b/README.sh @@ -36,6 +36,10 @@ while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Wait echo -n 3 | http -v :8080/foo; +# tag::logicerror[] +echo 17 | http -v :8080/foo?error=1 +# end::logicerror[] + # tag::kafkacat[] kafkacat -b :9092 -t test -o 0 -e -f 'p=%p|o=%o|k=%k|h=%h|v=%s\n' # end::kafkacat[] diff --git a/src/main/java/de/juplo/kafka/RestProducer.java b/src/main/java/de/juplo/kafka/RestProducer.java index e68fe66..67b342a 100644 --- a/src/main/java/de/juplo/kafka/RestProducer.java +++ b/src/main/java/de/juplo/kafka/RestProducer.java @@ -29,13 +29,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);