Switched from single-node (assign) to multi-instance (subscribe)
authorKai Moritz <kai@juplo.de>
Sun, 20 Jun 2021 17:51:13 +0000 (19:51 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 29 Jun 2021 18:29:41 +0000 (20:29 +0200)
commit43ea59755f9673864a3ef95250009f091e99a760
tree5272ef90d4b72aa845639d34bd2a6d8e1ec46c19
parentcbfe4b796266ff7b9689fb69c5a8efee8ebb130a
Switched from single-node (assign) to multi-instance (subscribe)

* TransferConsumer uses subscribe() instead of assign().
* The subscription happens during the instanciation of TransferConsumer.
* The restorage-process of the state happens in onPartitionsAssigned().
* To be able to reset all data, that belongs to a specific partition
  after a rebalance, in order to avoid state errors because of handling
  events several times, InMemoryTransferRepository must know, which
  partition a transfer belongs to.
* To achieve this, the partitioning algorithm is made known explicitly.
* On each rebalance, a mapping from the partions to the currently assigned
  instances is maintained.
* TransferController uses the explicitly known partitioning algorithm, to
  look up the partion for a requested transfer and decide, if the data is
  available locally.
* If not, it looks up the assigned instance in the maintained mapping and
  redirects the request.
application.yml [new file with mode: 0644]
pom.xml
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
src/main/java/de/juplo/kafka/payment/transfer/adapter/TransferConsumer.java
src/main/java/de/juplo/kafka/payment/transfer/adapter/TransferController.java
src/main/java/de/juplo/kafka/payment/transfer/adapter/TransferPartitioner.java [new file with mode: 0644]
src/main/java/de/juplo/kafka/payment/transfer/persistence/InMemoryTransferRepository.java
src/main/java/de/juplo/kafka/payment/transfer/ports/TransferRepository.java
src/test/java/de/juplo/kafka/payment/transfer/TransferServiceApplicationTests.java