WIP
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / persistence / kafka / KafkaChatHomeService.java
index b2ed284..a5d63fd 100644 (file)
@@ -17,7 +17,7 @@ public class KafkaChatHomeService implements ChatHomeService, ConsumerRebalanceL
 {
   private final Consumer<String, MessageTo> consumer;
   private final String topic;
-  private final long[] offsets;
+  // private final long[] offsets; Erst mal immer alles neu einlesen
   private final Map<UUID, ChatRoom>[] chatrooms;
 
 
@@ -29,14 +29,11 @@ public class KafkaChatHomeService implements ChatHomeService, ConsumerRebalanceL
     log.debug("Creating KafkaChatHomeService");
     this.consumer = consumer;
     this.topic = topic;
-    this.offsets = new long[numShards];
-    this.chatrooms = new Map<>[numShards];
-    for (int i=0; i< numShards; i++)
-    {
-      this.offsets[i] = 0l;
-      this.chatrooms[i] = chat
-    }
-    this.chatrooms = new Map[numShards];
+    // this.offsets = new long[numShards];
+    // for (int i=0; i< numShards; i++)
+    // {
+    //   this.offsets[i] = 0l;
+    // }
     this.chatrooms = new Map[numShards];
   }
 
@@ -53,13 +50,18 @@ public class KafkaChatHomeService implements ChatHomeService, ConsumerRebalanceL
       }
 
       int partition = tp.partition();
-      long unseenOffset = offsets[partition];
+      long unseenOffset = 0; // offsets[partition];
 
       log.info(
           "Loading messages from partition {}: start-offset={} -> current-offset={}",
           partition,
           unseenOffset,
           currentOffset);
+
+      consumer.seek(tp, unseenOffset);
+      chatrooms[partition]
+          .values()
+          .stream()
       handlers[partition] = new ChatRoomLoadingMessageHandlingStrategy(tp, currentOffset, unseenOffset);
     });
   }