projects
/
demos
/
kafka
/
chat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: The actual position has to be requested from the consumer
[demos/kafka/chat]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
chat
/
backend
/
implementation
/
kafka
/
DataChannel.java
diff --git
a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java
b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java
index
2fa4998
..
c13f713
100644
(file)
--- a/
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java
+++ b/
src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/DataChannel.java
@@
-147,11
+147,16
@@
public class DataChannel implements Runnable, ConsumerRebalanceListener
infoChannel.sendShardAssignedEvent(partition);
shardingPublisherStrategy
.publishOwnership(partition)
infoChannel.sendShardAssignedEvent(partition);
shardingPublisherStrategy
.publishOwnership(partition)
- .doOn
Next
(instanceId -> log.info(
- "
Instance {} was published
as owner of shard {}",
+ .doOn
Success
(instanceId -> log.info(
+ "
Successfully published instance {}
as owner of shard {}",
instanceId,
partition))
instanceId,
partition))
- .subscribe();
+ .doOnError(throwable -> log.error(
+ "Could not publish instance {} as owner of shard {}: {}",
+ instanceId,
+ partition,
+ throwable))
+ .block();
});
consumer.resume(partitions);
});
consumer.resume(partitions);
@@
-266,6
+271,11
@@
public class DataChannel implements Runnable, ConsumerRebalanceListener
KafkaChatMessageService kafkaChatRoomService =
(KafkaChatMessageService) chatRoomData.getChatRoomService();
KafkaChatMessageService kafkaChatRoomService =
(KafkaChatMessageService) chatRoomData.getChatRoomService();
+ log.debug(
+ "Loaded message from partition={} at offset={}: {}",
+ partition,
+ offset,
+ message);
kafkaChatRoomService.persistMessage(message);
}
kafkaChatRoomService.persistMessage(message);
}
@@
-274,7
+284,12
@@
public class DataChannel implements Runnable, ConsumerRebalanceListener
return IntStream
.range(0, numShards)
.filter(shard -> isShardOwned[shard])
return IntStream
.range(0, numShards)
.filter(shard -> isShardOwned[shard])
- .allMatch(shard -> nextOffset[shard] >= currentOffset[shard]);
+ .allMatch(shard ->
+ {
+ TopicPartition partition = new TopicPartition(topic, shard);
+ long position = consumer.position(partition);
+ return position >= currentOffset[shard];
+ });
}
private void pauseAllOwnedPartions()
}
private void pauseAllOwnedPartions()