an introduction to cqrs and axon framework
play

An introduction to CQRS and Axon Framework Finances forgotten - PowerPoint PPT Presentation

An introduction to CQRS and Axon Framework Finances forgotten treasure Allard Buijze allard.buijze@trifork.nl Allard Buijze Software Architect at Trifork Amsterdam ~ 15 years of web development experience Strong believer


  1. An introduction to CQRS and Axon Framework Finance’s ‘forgotten’ treasure Allard Buijze – allard.buijze@trifork.nl

  2. Allard Buijze � Software Architect at Trifork Amsterdam � ~ 15 years of web development experience � Strong believer in DDD and CQRS � Developer and initiator of Axon Framework � Java Framework for scalability and performance � www.axonframework.org

  3. Layered architecture

  4. Evolution of a Domain Model

  5. Evolution of a Domain Model

  6. Evolution of a Domain Model

  7. Evolution of complexity Source: ¡h*p://royal.pingdom.com/2008/01/09/the-­‑worst-­‑cable-­‑mess-­‑ever/ ¡

  8. Evolution of complexity private static final String PLAYER_COCKPIT_WATERFALL_ITEMS_QUERY = "(" + "select id, " + EntityType.NEWS_ITEM.ordinal() + " as entity_type, publish_date as sort_date " + SELECT ¡ "from news_item " + "where active = true and (" + NEWS_ITEM ¡ "poster_player_id = :playerId " + "or poster_player_id in (" + or ¡project ¡in ¡(… ¡ "select destination_friend_id from friendship where origin_friend_id = :playerId " + ") " + "or project_id in (" + status ¡= ¡‘OK’ ¡ "select distinct project_id " + or ¡project ¡in ¡(… ¡ "from donation " + "where donor_participant_id = :playerId and status = 'OK'" + ")" + UNION ¡ALL ¡ "or project_id in (" + DONATION ¡ "select project_id from ambassador_project where player_id = :playerId " + "))" + status ¡= ¡‘OK’ ¡ ") union all (" + "select id, " + EntityType.DONATION.ordinal() + " as entity_type, approval_date as sort_date " + "from donation " + "where status = 'OK' and (" + "donor_participant_id = :playerId " + or ¡raised_via_player ¡in ¡(… ¡ "or donor_participant_id in (" + "select destination_friend_id from friendship where origin_friend_id = :playerId" + ")" + "or raised_via_player_id = :playerId " + "or raised_via_player_id in (" + UNION ¡ALL ¡ "select destination_friend_id from friendship where origin_friend_id = :playerId" + FRIENDSHIP ¡ ") " + ") " + ") union all ( " + "select id, " + EntityType.FRIENDSHIP.ordinal() + " as entity_type, created as sort_date " + "from friendship " + "where origin_friend_id = :playerId or (origin_friend_id in ( " + "select destination_friend_id from friendship where origin_friend_id = :playerId " + ") and destination_friend_id <> :playerId)" + ") ";

  9. Layered architecture Web ¡Cache ¡ Session ¡replicaYon ¡ Method ¡invocaYon ¡Cache ¡ Worker ¡pools ¡ Query ¡Cache ¡ Distributed ¡2 nd ¡level ¡cache ¡

  10. Designed for high performance (?)

  11. Then vs Now 1970’s ¡ 2014 ¡

  12. Brought to us by the Financial Sector Sources ¡(ltr ¡*b): ¡guides.wikinut.com ¡(2x), ¡telegraph.co.uk, ¡commons.wikimedia.org, ¡usatoday.com ¡

  13. Brought to us by the Financial Sector CQRS ¡ Disruptor ¡(LMAX) ¡ Source: ¡mechaniYs.blogspot.com ¡

  14. CQRS Based Architecture

  15. CQRS Based Architecture Command ¡model ¡ ProjecYons ¡

  16. CQRS Based Architecture Command ¡model ¡ ProjecYons ¡

  17. CQRS Based Architecture Command ¡model ¡ ProjecYons ¡ T: ¡1 ¡/ ¡s ¡ T: ¡Thr. ¡20 ¡/ ¡s ¡ T: ¡10 ¡mln ¡/ ¡s ¡ T: ¡1 ¡mln ¡/ ¡s ¡ Resp. ¡< ¡10 ¡ms ¡ Resp: ¡< ¡100 ¡ms ¡ Resp. ¡< ¡100 ¡ms ¡ Resp: ¡< ¡10 ¡ms ¡

  18. Synchronizing models St Stored ¡ d ¡pr Ev Events procedur dures s Command ¡model ¡ ProjecYons ¡

  19. CQRS Based Architecture

  20. The power of ubiquitous events ReacYve ¡ Polling ¡ Push ¡ Cache ¡evicYon ¡ Real-­‑Yme ¡ Event ¡Sourcing ¡ LocaYon ¡transparency ¡ Systems ¡integraYon ¡

  21. Event Sourcing

  22. Event Sourcing Orders ¡ OrderItems ¡ ID ¡ Status ¡ ID ¡ OrderID ¡ Product ¡ Count ¡ 1 ¡ Return ¡shipment ¡rcvd ¡ 1 ¡ 1 ¡ Deluxe ¡Chair ¡ 1 ¡ 2 ¡ 1 ¡ ... ¡ ... ¡ vs ¡ Seq# ¡ Event ¡ 0 ¡ OrderCreatedEvent ¡ 1 ¡ ItemAddedEvent ¡(2x ¡Deluxe ¡Chair ¡-­‑ ¡€ ¡399) ¡ 2 ¡ ItemRemovedEvent ¡(1x ¡Deluxe ¡Chair ¡-­‑ ¡€ ¡399) ¡ 3 ¡ OrderConfirmed ¡ 4 ¡ OrderCancelledByUserEvent ¡ 5 ¡ ReturnShipmentReceived ¡

  23. Event Sourcing � Pros � Audit trail � Reconstruct query model(s) � Management reports since day 1 � Data analysis � Cons � Maintain history (upcasters) � Ever-growing

  24. Axon Framework � “CQRS Framework” for Java � Open source under Apache 2 License � Simplify CQRS based applications � Provides building blocks for CQRS applications � Current version*: 2.1 � More information: www.AxonFramework.org * ¡On ¡January ¡9 th , ¡2014 ¡

  25. CQRS Based Architecture

  26. Axon – Command Bus API @CommandHandler ¡ public ¡void ¡ handle(CreateToDoItemCommand ¡command) ¡{ ¡ ¡ ¡ ¡ ¡// ¡handle ¡command ¡ } ¡ commandBus .dispatch(commandMessage, ¡ new ¡VoidCallback() ¡{ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡ public ¡void ¡onSuccess() ¡{ ¡... ¡} ¡ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡ public ¡void ¡ onFailure(Throwable ¡cause) ¡{ ¡... ¡} ¡ }); ¡

  27. Axon – Event Bus API eventBus .publish( asEventMessage ( new ¡ToDoItemCompletedEvent( “todo1” ))); ¡ @EventHandler ¡ public ¡void ¡ onEvent(ToDoItemCompletedEvent ¡event) ¡ { ¡ ¡ ¡ ¡ ¡// ¡handle ¡event ¡ } ¡

  28. CQRS Based Architecture interface ¡AggregateRoot ¡ abstract ¡class ¡AbstractAggregateRoot ¡ ¡ interface ¡EventSourcedAggregateRoot ¡ abstract ¡class ¡ AbstractAnnotatedAggregateRoot ¡

  29. Apply ¡state ¡ Make ¡decisions ¡ Axon – Event Sourcing

  30. Event Sourcing - Testing � Given-when-then fixtures � Given some past events � When I apply a new Command � Expect these new Events fixture.given( new GameStartedEvent(…), new CallMadeEvent(…), new TurnChangedEvent(…) ) .when( new MakeCallCommand(…) ) .expectEvents( new CallMadeEvent(…) , new TurnChangedEvent(…) );

  31. Separate infrastructure from business logic A ¡ D ¡ B ¡ E ¡ C ¡

  32. Separate infrastructure from business logic A ¡ D ¡ B ¡ E ¡ C ¡

  33. Separate infrastructure from business logic A ¡ D ¡ B ¡ E ¡ C ¡

  34. Spring configuration - Simple

  35. Spring configuration – High performance

  36. Spring configuration – Distributed Events

  37. Spring configuration – Distributed Commands

  38. Infrastructure components in Axon � Single VM � SimpleCommandBus � SimpleEventBus � High Performance � DisruptorCommandBus � ... � Distributed � DistributedCommandBus + JGroupsConnector � ClusteringEventBus + AMQP Terminal � ...

  39. Axon Roadmap � More distributed implementations � Improved OSGi support � DSL for definition of Command & Events � IDE Plugins � High performance Event Store

  40. Axon Framework – Some cases � Finance � Process automation in a top 50 bank � Trading engine for ETF (index trackers) trading � Pension fund calculations at a large bank � On-line payment processing � Gaming � On-line bridge platform (bridgebig.com) � On-line casino (casumo.com) � Healthcare � Electronic Medical Record for the Geriatric Healthcare � Tracking and Tracing of equipment for dental implants � Aviation � Optimizing aircraft movement at a large European airport

  41. The next time…

  42. More information: axonframework.org Allard Buijze abu@trifork.com

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend