/// <summary> /// The message loop to process fluent requests from REST endpoint. /// </summary> /// <param name="cancellationToken">task cancellation token</param> /// <returns></returns> private async Task RunAsync(CancellationToken cancellationToken = default(CancellationToken)) { Console.WriteLine("\nStarting Message loop...!\n"); var channel = await RequestChannel.CreateAsync(cancellationToken); while (!cancellationToken.IsCancellationRequested) { var nextRequest = await channel.TryReadNextAsync(cancellationToken); if (nextRequest != null) { Console.WriteLine($"Received request: {nextRequest.RequestId}"); // // Don't call await here. Since this call is happening in the message loop // the parent method will not be returned. By not calling await, we can // prcoess requests concurrenlty. With await the requests will be processed // async-serially. // HandleRequestAsync(nextRequest.RequestId, nextRequest.RequestModel, cancellationToken); } await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken); } Console.WriteLine("\nMessage loop Stopped...!\n"); }
public async Task <IActionResult> Post([FromBody] FluentRequestModel fluentRequestPayload) { if (fluentRequestPayload == null) { return(BadRequest(new Exception("Failed to parse the json payload, make sure it is valid"))); } var channel = await RequestChannel.CreateAsync(); var requestId = await channel.WriteAsync(fluentRequestPayload); var pollingUrl = Link($"GetCreateStatus/{requestId}"); HttpContext.Response.Headers["Location"] = pollingUrl; return(Ok(new BeginCreateResponse(pollingUrl))); }