What I learned today — 5 February 2018
Modelling Sagas with the Axon Framework
What works really nicely when modelling sagas using the Axon Framework is to first just test and implement, using axon-test and doing TDD, the flow of the saga, without implementing any other business logic. This means you’re just testing the sequence of events and commands, and the only state you need to carry is the aggregate identifier. The SagaTestFixture
makes this very easy, because you are setting up the fixture with past events and then expecting the next event or command. All other logic can be implemented in the aggregate (or saga) at a different stage.
Null-safety with Kotlin
By using safe calls and the Elvis operator you can elegantly handle the possibility of a null reference with Kotlin. For example:
this.commandGateway?.send<Any>(command) ?: throw IllegalStateException ("CommandGateway can not be null")
The safe call, ?.
, returns null if the left hand side of it is null, and the Elvis operator, ?:
, will execute it’s right hand side if the expression on it’s left is null.