//public async Task<object> ProcessProxyRequestAsync(string proxyChannel, object req) public async Task <HttpResponseMessageWrapperEx> ProcessProxyRequestAsync(HttpRequestMessageWrapperEx request) { var proxyChannel = request.GetSourceChannel(); var requestId = request.GetRequestId(); var connectionId = Context.ConnectionId; ProxyRequests.AddOrUpdate(requestId, connectionId, (key, val) => { return(val); }); Console.WriteLine($"srrs:Proxy [{proxyChannel}] connected and request [{requestId}] received."); if (_cts.IsCancellationRequested) { return(null); } var dispatcherChannel = ServiceTypesUtil.GetProxyServiceName(proxyChannel); Console.WriteLine($"srrs:Sending request to dispatcher [{dispatcherChannel}] [{requestId}]."); var dispatcherConnectionId = GetDispatcherConnectionId(dispatcherChannel); await Clients.Client(dispatcherConnectionId).SendAsync("dispatch", request); if (_cts.IsCancellationRequested) { return(null); } Console.WriteLine($"srrs:Awaiting response from dispatcher [{dispatcherChannel}]."); HttpResponseMessageWrapperEx response = null; while (true) { if (_cts.IsCancellationRequested) { return(null); } Task.Delay(100).Wait(); if (DispatcherResponses.TryRemove(requestId, out response)) { break; } } return(response); }
private async Task <HttpResponseMessageWrapperEx> AwaitResponseFromDispatcher(string requestId, string dispatcherChannel) { Console.WriteLine($"srrs:Awaiting response from dispatcher [{dispatcherChannel}]."); HttpResponseMessageWrapperEx response = null; while (true) { if (_cts.IsCancellationRequested) { return(null); } await Task.Delay(150); if (DispatcherResponses.TryRemove(requestId, out response)) { break; } } return(response); }
public Task DispatcherResponseAsync(string dispatcherChannel, string requestId, HttpResponseMessageWrapperEx response) { Console.WriteLine($"srrs:Received message from dispatcher [{dispatcherChannel}]."); DispatcherResponses.AddOrUpdate(requestId, response, (key, val) => { return(val); }); return(Task.CompletedTask); }