public static async Task <TRes> RequestAsync <TReq, TRes>(this IGatePublisher gatePublisher, string serviceName, string topicName, TReq gateRequest, int requestTimeoutInSeconds, CancellationToken cancellationToken) { serviceName = serviceName ?? throw new ArgumentNullException(nameof(serviceName)); topicName = topicName ?? throw new ArgumentNullException(nameof(topicName)); var message = Serializer.Serialize(gateRequest); var reply = await gatePublisher.RequestAsync(serviceName, topicName, message, requestTimeoutInSeconds, cancellationToken); return(Serializer.Deserialize <TRes>(reply)); }
public async Task RequestAsync(string topicName, string serviceName, string servicePath) { var gateRequest = await HttpContext.Request.ToGateRequestAsync(servicePath); try { var gateResponse = await _gatePublisher.RequestAsync <GateRequest, GateResponse>(serviceName, topicName, gateRequest, _options.RequestTimeoutInSeconds, HttpContext.RequestAborted); await gateResponse.PopulateHttpResponseAsync(HttpContext.Response); } catch (TimeoutException ex) { _logger.LogError(ex, "Request error [{}]", HttpContext.Request.Path); HttpContext.Response.StatusCode = StatusCodes.Status504GatewayTimeout; } }