# How to define an event sourced command?

PREREQUISITE


  1. Open .kdomain file, first define a command-set along with the association to the event-stream.

    For example to define a command create lottery which will raise events defined in event-stream LotteryStream:

    command-set[LotteryStream] Lottery{ ... }
    
  2. Define the command inside the command-set with the following details:

    • specify the input (if any),
    • define one or more pre-conditions(if any)
    • specify the events that this command would raise(if any)
    • specify the output (if any)
    • define one or more post-condition (if any)






     







    command-set Lottery {
      command create{
          input(lotteryName:String,amount:Int)
          pre{
            condition AmountMustBeGreaterThanZero => `input.amount>0` failing "Amount must be greater than 0"
          }
          event-raised(created:LotteryCreated)
          output(result:String)
          post{
           condition lotteryCreated => ...
          }
        }
    }
    
  3. In order to implement the command logic follow steps listed here.