public void Activate() { _system.Root.Send(_actorFactory.GetActor <IDIActor>(), new DIActor.Ping("no-name-from-interface")); Thread.Sleep(TimeSpan.FromSeconds(1)); _system.Root.Send(_actorFactory.GetActor <IDIActor>("named-from-interface"), new DIActor.Ping("named-from-interface")); Thread.Sleep(TimeSpan.FromSeconds(1)); _system.Root.Send(_actorFactory.GetActor <DIActor>(), new DIActor.Ping("no-name")); Thread.Sleep(TimeSpan.FromSeconds(1)); _system.Root.Send(_actorFactory.GetActor <DIActor>("named"), new DIActor.Ping("named")); }
public async Task SendAsync <T>(object message) where T : IActor { try { await Task.Yield(); actorSystem.Root.Send(actorFactory.GetActor <T>(), message); } catch (Exception ex) { logger.LogError("", ex); } }
public async Task ReceiveAsync(IContext context) { switch (context.Message) { case ReceiveCommands receive: { var commands = await _sqsClient.ReceiveCommandBatchAsync(receive.NumberOfCommands); if (commands.Count() > 0) { foreach (var command in commands) { var handler = _factory.GetActor(command); var message = _mapper.Map(command); handler.Tell(message); } context.Self.Tell(new ReceiveCommands()); } else { context.Self.Tell(new BackOff()); } } break; case BackOff backOff: { await Task.Delay(TimeSpan.FromSeconds(backOff.DelayInSeconds)); context.Self.Tell(new ReceiveCommands()); } break; } }
public void Activate() { var actorPing = _actorFactory.GetActor <PingActor>(); //var actorPong = _actorFactory.GetActor<PongActor>(); _context.Send(actorPing, new Ping(1)); }
public async Task ReceiveAsync(IContext context) { var msg = context.Message; if (msg is Pong p) { Console.WriteLine($"Hello {p.Message} {GetHashCode()}"); if (p.Iteration < 100) { await Task.Delay(TimeSpan.FromSeconds(1)); context.Send(actorFactory.GetActor <PingActor>(), new Ping(p.Iteration + 1)); } } }
public async Task ReceiveAsync(IContext context) { switch (context.Message) { case Started _: { context.SetReceiveTimeout(TimeSpan.FromSeconds(5)); } break; case SendRequest sendRequest: { using (_logger.TimeOperation("{ActorId} sending request to {Url}", context.Self.Id, sendRequest.Url)) using (var client = _httpClientFactory.CreateClient(nameof(Dispatcher))) { var content = new StringContent(sendRequest.Data, Encoding.UTF8, "application/json"); await client.PostAsync(sendRequest.Url, content); } var deleter = _actorFactory.GetActor <Deleter>(); deleter.Tell( new DeleteCommand { CommandId = sendRequest.CommandId, ReceiptHandle = sendRequest.ReceiptHandle }); } break; case ReceiveTimeout _: { context.Self.Stop(); } break; } }
public void Activate() { _context.Send(_actorFactory.GetActor <DIActor>(), new DIActor.Ping("no-name")); _context.Send(_actorFactory.GetActor <DIActor>("named"), new DIActor.Ping("named")); }
public PID Get <T>() where T : IActor { return(_factory.GetActor <T>()); }
public PID GetActor <TActor>() where TActor : IActor => _actorFactory.GetActor <TActor>();
public void Activate() { actorFactory.GetActor <DIActor>().Tell(new DIActor.Ping("no-name")); actorFactory.GetActor <DIActor>("named").Tell(new DIActor.Ping("named")); }
public PID GetParentActor() { return(_actorFactory.GetActor <RequestActor>(ActorNames.RequestActor)); }