johanhaleby / occurrent

Unintrusive Event Sourcing Library for the JVM
https://occurrent.org
124 stars 16 forks source link

Create SagaDSL that combines subscription model, deadline api, application service etc #124

Open johanhaleby opened 2 years ago

johanhaleby commented 2 years ago

E.g.

val saga = SagaDSL(subscriptionModel, deadlineScheduler, applicationService, eventStore)

val sagaInstance = saga.initializedOn<GameCreated> thenIf<PlayerJoinedGame>(notReceivedWithin(10, MINUTES)) do { gameCreated ->
      Game.close(gameCreated.gameId)
}

Resulting events from Game.close(gameCreated.gameId) is stored using the AS. A subscription is automatically created on GameCreated and PlayerJoinedGame. Saga state could be stored in a stream in an event store, which is why we pass that in as a parameter to SagaDSL.

johanhaleby commented 2 years ago

Other scenarios

saga.initializedOn<GameCreated> thenWaitFor<PlayerJoinedGame, PlayerJoinedGame, FirstPlayerMadeMove>(atMost(10, MINUTES)) do { (gameCreated, playerJoinedGame1, playerJoinedGame2, firstPlayerMadeMove) ->
      emailService.send(..)
} ifNotFulfilled { listOfAllReceivedEventsThusFar ->
  ... 
}