private Task SendResponseAsync( IMqResponseFeature mqResponse, IHttpResponseFeature httpResponse, IHeaderConverter headerConverter ) { var needPublish = false; var needAck = mqResponse.AckDeliveryTag.HasValue; if (mqResponse.Exchange != null) { MergeResponseHeaders(mqResponse, httpResponse, headerConverter); needPublish = true; } return(Task.Run(() => { if (needPublish) { _mqConnection.Model.BasicPublish(mqResponse.Exchange, mqResponse.RoutingKey, mqResponse.Mandatory, mqResponse.Properties, GetBody(mqResponse)); } if (needAck) { _mqConnection.Model.BasicAck(mqResponse.AckDeliveryTag.Value, multiple: false); } })); }
private static void MergeResponseHeaders(IMqResponseFeature mqResponse, IHttpResponseFeature httpResponse, IHeaderConverter headerConverter) { var headers = mqResponse.Properties.Headers; foreach (var item in httpResponse.Headers) { headers[item.Key] = headerConverter.Write(item.Value); } }
private IHttpResponseFeature CreateHttpResponse(IMqResponseFeature mqResponse) { var httpResponse = new HttpResponseFeature { Body = mqResponse.BodyStream, }; return(httpResponse); }
private static Byte[] GetBody(IMqResponseFeature mqResponse) { if (mqResponse.Body != null) { return(mqResponse.Body); } if (mqResponse.BodyStream != null && mqResponse.BodyStream is MemoryStream memoryStream) { return(memoryStream.ToArray()); } return(null); }