AxonFramework / AxonBank

Simple virtual bank application to showcase features of Axon Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changes to Write model are not reflected on Frontend

burakozhan opened this issue · comments

I have tried to extend this example by adding a "delete bank account" feature. (Ok the name is misleading, I just zero the balance)
I do set the balanceInCents in the BankAccount Aggregate to 0 by using an eventHandler. This should be quite simple and straight forward. When I now do following actions :

  1. Create bank account
  2. Deposit 3
  3. Delete account
  4. Deposit 5

Expected result in Frontend would be to have 5 as the balance displayed.
By using Logs on the BankAccount Aggregate I do see that the actual balance is 5.
Since the read model uses it's own EventHandlers to calculate the balance again instead of 5 I get displayed a balance of 8.

I am trying to learn to use the axon framework with this simple example, but it just confuses me.
There is something wrong with this code and I can't quite put my finger on it since I am new to axon.

I don't see the point in implementing my business logic of "delete" (or "reset the balance to 0") multiple times. Can someone more experienced please elaborate on this ?

So, it seems that your third action, 'Delete Account' wasn't handled correctly or not at all on the read side of the system.
You probably need to add an @EventHandler function to the read side which handles the 'Delete Account' event you've created to update the read side.

And yes, in this example it seems like your doubling your work, as it's changing the Aggregate state and has to change the read side to reflect the change.

The read/query side is however not tied to reflect the aggregate.
You could add a Event Handling class (a class with @EventHandler annotated functions) for all bank events to update a search client. Or an Event Handling class which by getting triggered by a 'Delete Account'-event knows it needs to notify the owner of the bank account by sending an email.
A multitude of use cases could be imagined where the query side does not directly reflect the aggregate state and that's when your not duplicating logic.|

I hope the above explanation helps somewhat. If not, I'd gladely elaborate more on it.

Closing this issue due to prolonged inactivity. Feel free to keep commenting on this.