public async Task <IActionResult> PostAsync() { string serviceUri = this.serviceContext.CodePackageActivationContext.ApplicationName + "/" + this.configSettings.ActorBackendServiceName; IMyActor proxy = ActorProxy.Create <IMyActor>(ActorId.CreateRandom(), new Uri(serviceUri)); // Create and start a new activity representing the beginning of this outgoing request Activity activity = new Activity("HttpOut"); activity.Start(); DateTimeOffset startTime = DateTimeOffset.UtcNow; // Extract the request id and correlation context headers so they can be passed to the callee, which // will create the correlation Activity currentActivity = Activity.Current; string requestId = currentActivity.Id; Dictionary <string, string> correlationContextHeader = new Dictionary <string, string>(); foreach (var pair in currentActivity.Baggage) { correlationContextHeader.Add(pair.Key, pair.Value); } try { await proxy.StartProcessingAsync(requestId, correlationContextHeader, CancellationToken.None); } catch (Exception) { throw; } finally { //always stop activity if it was started if (activity != null) { activity.Stop(); } DateTimeOffset endTime = DateTimeOffset.UtcNow; DependencyTelemetry telemetry = new DependencyTelemetry( "HTTP", // dependencyTypeName serviceUri, // target "POST " + serviceUri, // dependencyName serviceUri, // data startTime, // startTime endTime - startTime, // duration "OK", // resultCode true); // success telemetry.Id = activity.Id; TelemetryClient client = new TelemetryClient(TelemetryConfiguration.Active); client.TrackDependency(telemetry); } return(this.Json(true)); }
public async Task <IActionResult> PostAsync() { string serviceUri = this.serviceContext.CodePackageActivationContext.ApplicationName + "/" + this.configSettings.ActorBackendServiceName; IMyActor proxy = ActorProxy.Create <IMyActor>(ActorId.CreateRandom(), new Uri(serviceUri)); await proxy.StartProcessingAsync(CancellationToken.None); return(this.Json(true)); }
private static async Task <int> MakeMove( IMyActor p1, IMyActor p2, ActorId gameId) { Random rand = new Random(); int c = await p1.GetCountAsync(); await Task.Delay(rand.Next(500, 2000)); return(c); }
public async Task <IActionResult> PostAsync(string actorType) { switch (actorType) { case "netcore": string serviceUriNetCore = _serviceContext.CodePackageActivationContext.ApplicationName + "/" + _configSettings.ActorBackendServiceNetCoreName; INetCoreActor proxyNetCore = ActorProxy.Create <INetCoreActor>(ActorId.CreateRandom(), new Uri(serviceUriNetCore)); long x = await proxyNetCore.GetCountAsync(CancellationToken.None); // await proxyNetCore.StartProcessingAsync(CancellationToken.None); break; default: string serviceUri = _serviceContext.CodePackageActivationContext.ApplicationName + "/" + _configSettings.ActorBackendServiceName; IMyActor proxy = ActorProxy.Create <IMyActor>(ActorId.CreateRandom(), new Uri(serviceUri)); await proxy.StartProcessingAsync(CancellationToken.None); break; } return(Json(true)); }
/// <summary> /// This is the entry point of the service host process. /// </summary> private static void Main() { try { // This line registers an Actor Service to host your actor class with the Service Fabric runtime. // The contents of your ServiceManifest.xml and ApplicationManifest.xml files // are automatically populated when you build this project. // For more information, see https://aka.ms/servicefabricactorsplatform ActorRuntime.RegisterActorAsync <MyActor>( (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult(); Console.WriteLine("Actor runtime registration completed"); // Speak with actor a few times. I.e. send messages. // Create a randomly distributed actor ID ActorId actorId = ActorId.CreateRandom(); // This only creates a proxy object, it does not activate an actor or invoke any methods yet. IMyActor myActor = ActorProxy.Create <IMyActor>(actorId, new Uri("fabric:/MyApp/MyActorService")); // Create the token source. CancellationTokenSource source = new CancellationTokenSource(); CancellationToken cts = source.Token; // This will invoke a method on the actor. If an actor with the given ID does not exist, it will // be activated by this method call. myActor.SetCountAsync(1, cts); Thread.Sleep(Timeout.Infinite); } catch (Exception e) { ActorEventSource.Current.ActorHostInitializationFailed(e.ToString()); throw; } }
private async Task <IActionResult> SetActorCount(IMyActor actor, int value) => SuccessResult(await actor.SetCountAsync(value, CancellationToken.None));
private async Task <IActionResult> GetActorCount(IMyActor actor) => SuccessResult(await actor.GetCountAsync(CancellationToken.None));