Domain Module

Specific Commands

Recipe Test
  • Handler
handler[LotteryStream] LotteryStream All

handler[LotteryStream] A {
    group A(event) //this event is defined in LotteryStream module
}
  • Domain: functions defined here can return any of the primitive or any data defined in data module. These functions can be used by ‘pre’ and ‘post’ when they return boolean(predicate) and ‘let’ can use any of these.
domain Lottery { //define-only {
    function lotteryNameExists(lotteryName:String):Boolean
}
  • Aggregate and Command :
aggregate[LotteryStream] Lottery {
 domain-ref lottery:Lottery
 command create {
    input(lotteryName:String, amount:Int) {
        //let isStartConnector:Boolean = `connectorName == "START"` //let can come here, this is just an example
    }
    pre {
        //let isMiTask:Boolean = taskDomain.isMiTask(input.taskId) //let can come here, this is just an example
        require lotterMustNotExist "Lottery must not exist" => !(lottery.lotteryMustExist(input.lotteryName))
    }
    post {
        //let isMiTask:Boolean = taskDomain.isMiTask(input.taskId) //let can come here, this is just an example
        require lotterMustExist "Lottery must exist" => `true`
    }
    event-raised(created:LotteryCreated) // OR event-raised something(a:XXFired)

    output(taskId:ObjectId?)
 }
  • Command-queue: Define the command queue and mention that with any command, then events will be processed in sync with this command queue
command-queue BigBoss
command[BigBoss] pullTask {
    input(taskId: ObjectId, userName: String)
    event-raised(allocated:TaskAllocated)
}

Recipes

Handler: LotteryStreamAllHandlerCode or LotteryStreamAHandlerCode gets generated under src. LotteryStreamAllHandler is the interface under src-gen, LotteryStreamAllHandlerCode extends LotteryStreamAHandler. Anytime definition changes, LotteryStreamAllHandlerCode regenerates, and any mismatch would be guided by the compiler.

override def handle(event: LotteryCreated, context: EventContext): Unit = ??? //for all the events handle method gets generated

Domain And Function: LotteryDomainCode gets generated and functions are defined here. One LotteryDomain interface also gets generated under src-gen and LotteryDomainCode extends that interface, so that any time any changes in the definition then compiler make sure that there is no orphan method or any method definition is not overridden by the Code file. If define-only mentioned then dont have to provide the implementation. Intention is to define the interface only.

override def lotteryNameExists(lotteryName:String):Boolean = ???

Aggregate and Command: LotteryAggregateCommands and LotteryAggregateCode gets generated. First one is the interface and the later one implements that. LotteryAggregateCommands is under src-gen and anytime defintion changes its get regenerated, and compiler guides us to fix the mismatch.

override def create = CreateCommand {
        import CreateCommand._;
        input: Input =>
        LotteryWriter().save(LotteryRow(lotteryName = input.lotteryName, amount = input.amount, open = false))
}

CommandQueue:BigBossCommandQueue, BigBossCommandQueueCode class and object

override def receive: Receive = { //write code here to process the event
}

Test

  • domain-function
  • command
  • Handler