consumer.seek(topicPartition, nextOffset[partition]);
});
+
+ consumer.resume(partitions);
}
@Override
if (loadInProgress)
{
- loadChatRooms(records);
+ loadChatRoom(records);
if (isLoadingCompleted())
{
log.info("Loading of messages completed! Pausing all owned partitions...");
+ pauseAllOwnedPartions();
+ log.info("Resuming normal operations...");
loadInProgress = false;
}
}
else
{
- createChatRooms(records);
+ if (!records.isEmpty())
+ {
+ throw new IllegalStateException("All owned partitions should be paused, when no load is in progress!");
+ }
}
}
catch (WakeupException e)
log.info("Exiting normally");
}
- private void loadChatRooms(ConsumerRecords<String, AbstractMessageTo> records)
+ private void loadChatRoom(ConsumerRecords<String, AbstractMessageTo> records)
{
for (ConsumerRecord<String, AbstractMessageTo> record : records)
{
}
}
-
- private void createChatRooms(ConsumerRecords<String, AbstractMessageTo> records)
- {
- for (ConsumerRecord<String, AbstractMessageTo> record : records)
- {
- UUID chatRoomId = UUID.fromString(record.key());
-
- switch (record.value().getType())
- {
- case COMMAND_CREATE_CHATROOM:
- log.info("Received create-request for chat room: {}", chatRoomId);
- createChatRoom(
- chatRoomId,
- (CommandCreateChatRoomTo) record.value(),
- record.partition());
- break;
-
- default:
- log.debug(
- "Ignoring message for chat-room {} with offset {}: {}",
- chatRoomId,
- record.offset(),
- record.value());
- }
-
- nextOffset[record.partition()] = record.offset() + 1;
- }
- }
-
private void createChatRoom(
UUID chatRoomId,
CommandCreateChatRoomTo createChatRoomRequestTo,
.allMatch(shard -> nextOffset[shard] >= currentOffset[shard]);
}
+ private void pauseAllOwnedPartions()
+ {
+ consumer.pause(IntStream
+ .range(0, numShards)
+ .filter(shard -> isShardOwned[shard])
+ .mapToObj(shard -> new TopicPartition(topic, shard))
+ .toList());
+ }
+
private void putChatRoom(
UUID chatRoomId,