From 675874c8629cf9392876c42df4bc881c8227049e 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 | 4 ++++ src/main/java/de/juplo/kafka/RestProducer.java | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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); -- 2.20.1