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>
Wed, 23 Jun 2021 20:24:44 +0000 (22:24 +0200)
commit225fdb5fe597b10ea29ee56895aa2b0df98e0604
tree12e39627bb93bc071d9b86ebf00b9449753efee2
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