Exemplo n.º 1
0
        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);
                }
            }));
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private IHttpResponseFeature CreateHttpResponse(IMqResponseFeature mqResponse)
        {
            var httpResponse = new HttpResponseFeature
            {
                Body = mqResponse.BodyStream,
            };

            return(httpResponse);
        }
Exemplo n.º 4
0
        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);
        }