//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); }
public async Task <HttpResponseMessageWrapperEx> ProcessProxyRequestAsync(HttpRequestMessageWrapperEx request) { var requestId = request.GetRequestId(); var proxyChannel = request.GetSourceChannel(); var dispatcherChannel = ServiceTypesUtil.GetProxyServiceName(proxyChannel); // simpleton routing Console.WriteLine($"srrs:Request [{requestId}] received on proxy channel [{proxyChannel}]."); ProxyRequests.AddOrUpdate(requestId, Context.ConnectionId, (key, val) => { return(val); }); if (_cts.IsCancellationRequested) { return(null); } await ForwardRequestToDispatcher(requestId, request, dispatcherChannel); if (_cts.IsCancellationRequested) { return(null); } var response = await AwaitResponseFromDispatcher(requestId, dispatcherChannel); return(response); }