Skip to content

Command execution

Andrey Leskov edited this page Oct 21, 2016 · 14 revisions

##Overview GridDomain supports command execution in two modes: fully asynchronous non-blocking and synchronous, waiting for given event by timeout. In both cases interface IGridDomainNode is used. ###Command asynchronous execution Common way to execute commands is fire-and forget

        var command = new CreateOrderCommand(orderNum);
        GridNode.Execute(command);
        //add any waiting here
        var order = LoadAggregate<OrderAggregate>(command.OrderId);
        Assert.AreEqual(command.OrderNum, order.Num);

We are not waiting and command is processed asynchronously, on different thread or machine. We don't know how much time command execution will take, and we don't wait for command faults.

Command results can be obtained only from read model after some period of time. Any command fault will be ignored. You can find example in unit test

###Waiting for messages from event bus

GridDomain has functionality to wait any message coming from internal event bus. Quick example :

  var cmd = new CreateAndChangeAggregateCommand(Guid.NewGuid());
  Task<IWaitResults> waiter = GridNode.NewWaiter()
                                  .Expect<SampleAggregateChangedEvent>(e => e.SourceId == cmd.AggregateId)
                                  .And<SampleAggregateCreatedEvent>(e => e.SourceId == cmd.AgregateId)
                                  .Or<IFault<SampleAggregateChangedEvent>>( f => f.Message.SourceId == cmd.AggregateId)
                               .Create(Timeout);
                     waiter.Wait();

waiter is created in Thread

Clone this wiki locally