Exemplo n.º 1
0
        public override async Task ReceiveAsync(IContext context)
        {
            Task task = context.Message switch
            {
                PingCmd cmd => HandlePing(context, cmd),
                ExceptionPoison cmd => HandleExceptionPoison(context, cmd),
                NoAnswerPoison cmd => HandleNoAnswerPoison(context, cmd),
                SleepPoison cmd => HandleSleepPoison(context, cmd),

                Started _ => Started(context),
                _ => base.ReceiveAsync(context)
            };

            try
            {
                await task;
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Failed PingGrain");
                context.Respond(new DeadLetterResponse
                {
                    Target = context.Self
                });
            }
        }
        public Task HandleSleepPoison(IContext context, SleepPoison cmd)
        {
            logger.LogInformation($"PongGrain.HandleSleepPoison");

            try
            {
                this.sleepCounter++;
                context.Respond(new PoisonResponse());
                return(Task.CompletedTask);
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Failed in HandleSleepPoison");
                context.Respond(new PoisonResponse());
            }
            return(Task.CompletedTask);
        }