From: Kai Moritz Date: Mon, 9 Jan 2023 22:25:22 +0000 (+0100) Subject: WIP X-Git-Tag: TEST~10 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=25c6532098a482c2ad28ffd70de6f0006a5047d8;p=demos%2Fkafka%2Fchat WIP --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java index 1eef2739..c61a1cc6 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java @@ -17,7 +17,7 @@ import java.util.regex.Pattern; @ToString(of = { "user", "id" }) class MessageTo { - final static Pattern SPLIT_ID = Pattern.compile("^([a-z-]+)--([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$"); + final static Pattern SPLIT_ID = Pattern.compile("^([a-z-]+)--([0-9]+)$"); private String id; private Long serial; private LocalDateTime time; @@ -28,19 +28,18 @@ class MessageTo Matcher matcher = SPLIT_ID.matcher(id); if (!matcher.matches()) throw new RuntimeException("MessageTo with invalid ID: " + id); - UUID uuid = UUID.fromString(matcher.group(2)); + Long messageId = Long.parseLong(matcher.group(2)); String user = matcher.group(1); - return new Message(Message.MessageKey.of(user, uuid), serial, time, text); + return new Message(Message.MessageKey.of(user, messageId), serial, time, text); } static MessageTo from(Message message) { return new MessageTo( - message.getId(), + message.getId() + "--" + message.getUsername(), message.getSerialNumber(), message.getTimestamp(), - message.getUsername(), message.getMessageText()); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java index 200e323f..ac249fc7 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java @@ -1,6 +1,5 @@ package de.juplo.kafka.chat.backend.persistence.storage.mongodb; -import de.juplo.kafka.chat.backend.api.ChatRoomTo; import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import reactor.core.publisher.Flux; @@ -15,42 +14,9 @@ public class MongoDbStorageStrategy implements StorageStrategy { chatroomFlux .log() - .doFirst(() -> - { - try - { - generator.useDefaultPrettyPrinter(); - generator.writeStartArray(); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - }) - .doOnTerminate(() -> - { - try - { - generator.writeEndArray(); - generator.close(); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - }) + .map(ChatRoomTo::from) .subscribe(chatroom -> { - try - { - ChatRoomTo chatroomTo = ChatRoomTo.from(chatroom); - generator.writeObject(chatroomTo); - writeMessages(chatroomTo, chatroom.getMessages()); - } - catch (IOException e) - { - throw new RuntimeException(e); - } }); } catch (IOException e)