private void CreateActor(object cancellationToken) { ActorId actorId = ActorId.CreateRandom(); ITestActor testActor = ActorProxy.Create <ITestActor>(actorId); testActor.SetCountAsync(10, (CancellationToken)cancellationToken).Wait(); }
/// <summary> /// This is the main entry point for your service instance. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { try { // TODO: Replace the following sample code with your own logic // or remove this RunAsync override if it's not needed in your service. long iterations = 0; ITestActor actor = ActorProxy.Create <ITestActor>(ActorId.CreateRandom()); while (true) { cancellationToken.ThrowIfCancellationRequested(); ServiceEventSource.Current.ServiceMessage(this.Context, $"{nameof(TestStateless)} Working-{++iterations}"); await actor.SetCountAsync((int)iterations, cancellationToken); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); } } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(this.Context, $"Exception: {ex}"); throw; } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); ITestActor actor = ActorProxy.Create <ITestActor>(ActorId.CreateRandom(), new Uri("fabric:/ServiceFabricTest/TestActorService")); var retval = actor.GetCountAsync(new CancellationToken()); Console.Write(retval.Result); Console.ReadLine(); // Had to specific partion here // See https://stackoverflow.com/questions/36157778/accessing-stateless-service-via-serviceproxy-fails-asp-net-5-web-api-project-t ITestStatefulService service = ServiceProxy.Create <ITestStatefulService>(new Uri("fabric:/ServiceFabricTest/TestStatefulService"), new ServicePartitionKey(1)); var message = service.GetResultAsync(); Console.Write(message.Result); Console.ReadLine(); }
public TestAppServiceTests() { _actor = GetRequiredService <ITestActor>(); }