# How to define an event sourced command?
PREREQUISITE
- Define a domain module
- Define a stream module
- Before defining the command, the event stream has to be defined in a .kstream file and the module dependency of the stream on command must be added.
Open .kdomain file, first define a
command-setalong with the association to the event-stream.For example to define a command
createlottery which will raise events defined in event-stream LotteryStream:command-set[LotteryStream] Lottery{ ... }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 => ... } } }In order to implement the command logic follow steps listed here.