Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Discovering unknown with EventStorming ConFoo

Discovering unknown with EventStorming ConFoo

Mariusz Gil

March 14, 2019
Tweet

More Decks by Mariusz Gil

Other Decks in Programming

Transcript

  1. Reservation requested Reservation accepted Availability and Limits checked customer Reservation

    rejected How to handle rejections? Similar offer Proposed @mariuszgil
  2. Reservation requested Reservation accepted Availability and Limits checked customer Reservation

    rejected How to handle rejections? Similar offer Proposed agent @mariuszgil
  3. Airline ticket Api gateway Reservation requested Reservation accepted Availability and

    Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent @mariuszgil
  4. Airline ticket Api gateway Reservation requested Availability and Limits checked

    customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Reservation accepted @mariuszgil
  5. Airline ticket Api gateway Reservation requested Availability and Limits checked

    customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted @mariuszgil
  6. Airline ticket Api gateway Reservation requested Availability and Limits checked

    customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ @mariuszgil
  7. Airline ticket Api gateway Reservation requested Availability and Limits checked

    customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ How to handle service Downtimes? @mariuszgil
  8. Airline ticket Api gateway Reservation requested Availability and Limits checked

    customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ How to handle service Downtimes? Some customers Have phones Only! @mariuszgil
  9. Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits

    reached Account upgraded to higher status Register loyalty points @mariuszgil
  10. Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits

    reached Account Status upgraded Register loyalty points Upgrade account status @mariuszgil
  11. Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits

    reached Account Status upgraded Register loyalty points Upgrade account status required points Levels Account upgrading policy @mariuszgil
  12. Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits

    reached Account Status upgraded Register loyalty points Upgrade account status required points Levels Account upgrading policy Reservations and payments history c.service @mariuszgil
  13. Payment Registered Loyalty points calculated Upgrade limits reached Account Status

    upgraded Upgrade account status required points Levels Account upgrading policy Loyalty account Loyalty points registered Register loyalty points Reservations and payments history c.service @mariuszgil
  14. Payment Registered Loyalty points calculated Upgrade limits reached Account Status

    upgraded Upgrade account status required points Levels Account upgrading policy Loyalty account Loyalty points registered Register loyalty points Reservations and payments history c.service @mariuszgil
  15. @Entity // Mark this aggregate as a JPA Entity public

    class MyAggregate { @Id private String id; // fields containing state... @CommandHandler public MyAggregate(CreateMyAggregateCommand command) { // ... update state apply(new MyAggregateCreatedEvent(...)); } // constructor needed by JPA protected MyAggregate() { } } Event Command / Decision
  16. public class MyAggregateRoot { @AggregateIdentifier private String aggregateIdentifier; // fields

    containing state... @CommandHandler public MyAggregateRoot(CreateMyAggregate cmd) { apply(new MyAggregateCreatedEvent(cmd.getId())); } // constructor needed for reconstruction protected MyAggregateRoot() { } @EventSourcingHandler private void handleMyAggregateCreatedEvent(MyAggregateCreatedEvent event) { // make sure identifier is always initialized properly this.aggregateIdentifier = event.getMyAggregateIdentifier(); // ... update state } } Aggregate
  17. domain event domain event domain event domain event business logic

    application logic infrastructure domain event domain event command domain event policy process managers
  18. business logic application logic infrastructure domain event command saga domain

    event command domain event Compensate command policy policy
  19. public class OrderManagementSaga { private boolean paid = false; private

    boolean delivered = false; @Inject private transient CommandGateway commandGateway; @StartSaga @SagaEventHandler(associationProperty = "orderId") public void handle(OrderCreatedEvent event) { // client generated identifiers ShippingId shipmentId = createShipmentId(); InvoiceId invoiceId = createInvoiceId(); // associate the Saga with these values, before sending the commands SagaLifecycle.associateWith("shipmentId", shipmentId); SagaLifecycle.associateWith("invoiceId", invoiceId); // send the commands commandGateway.send(new PrepareShippingCommand(...)); commandGateway.send(new CreateInvoiceCommand(...)); } @SagaEventHandler(associationProperty = "shipmentId") public void handle(ShippingArrivedEvent event) { delivered = true; if (paid) { SagaLifecycle.end(); } } @SagaEventHandler(associationProperty = "invoiceId") public void handle(InvoicePaidEvent event) { paid = true; if (delivered) { SagaLifecycle.end(); } } // ... } Reactive Policy
  20. read model business logic application logic infrastructure read models domain

    event domain event domain event domain event read model read model read model
  21. public class MyCommandComponentTest { private FixtureConfiguration<MyAggregate> fixture; @Before public void

    setUp() { fixture = new AggregateTestFixture<>(MyAggregate.class); } @Test public void testFirstFixture() { fixture.given(new MyEvent(1)) .when(new TestCommand()) .expectSuccessfulHandlerExecution() .expectEvents(new MyEvent(2)); /* } } Event Command / Decision Event Event Aggregate Given When Then
  22. Event Command / Decision Aggregate Read model Reactive Policy Record

    Inserted / Changed / Deleted Insert / Update / Delete / Truncate / … Record / Table Select / View Trigger / Procedure