Ejemplo n.º 1
0
        private bool CommandReceived(ICommand command)
        {
            var sender = Sender;
            var ctx    = new CommandContext();

            try
            {
                Log.Info($"command received: {command.GetType()}");
                _state.Execute(ctx, command);
                ctx.Commit((events) => PersistAll(events, e =>
                {
                    _state.ApplyEvent(e);
                    Context.System.EventStream.Publish(e);
                    Log.Info($"event emited{e.GetType()}");
                }));
                DeferAsync(new CommandResponse(), (msg) =>
                {
                    if (sender != ActorRefs.NoSender)
                    {
                        sender.Tell(msg, ActorRefs.NoSender);
                    }
                });
            }
            catch (Exception exception)
            {
                sender.Tell(new CommandResponse(exception, false));
                throw;
            }

            return(true);
        }