From: Kai Moritz Date: Wed, 25 Jan 2023 17:45:53 +0000 (+0100) Subject: WIP:refactor X-Git-Tag: wip~12 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=9d516bb14312526e01aaf2fb5ce2c7fc549aa49f;p=demos%2Fkafka%2Fchat WIP:refactor --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java index 878d7888..88099c04 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java @@ -66,17 +66,6 @@ public class ChatRoom Message.MessageKey key = Message.MessageKey.of(user, id); - Mono other = Mono.defer(() -> service - .persistMessage(key, LocalDateTime.now(clock), text) - .doOnNext(m -> - { - Sinks.EmitResult result = sink.tryEmitNext(m); - if (result.isFailure()) - { - log.warn("Emitting of message failed with {} for {}", result.name(), m); - } - })); - Mono mono = service .getMessage(key) .handle((existing, sink) -> @@ -91,7 +80,16 @@ public class ChatRoom } }); - return mono.switchIfEmpty(other); + return mono.switchIfEmpty(Mono.defer(() -> service + .persistMessage(key, LocalDateTime.now(clock), text) + .doOnNext(m -> + { + Sinks.EmitResult result = sink.tryEmitNext(m); + if (result.isFailure()) + { + log.warn("Emitting of message failed with {} for {}", result.name(), m); + } + }))); }