Example #1
0
        /// <inheritdoc />
        public async Task Send(Uri baseUri, HttpRequestMessage request, AmqpRequestOptions options)
        {
            var props = _communication.Channel
                        .CreateBasicProperties()
                        .Prepare(request, baseUri);

            props.AppId = _option.ClientName;
            var correlationId = request.Headers.GetCorrelationHeader();

            if (correlationId != null)
            {
                props.CorrelationId  = correlationId;
                props.ReplyToAddress = new PublicationAddress(AmqpCommunication.ProtocolName, _exchange, AmqpCommunication.ClientResponseQueue);
            }

            var body = await request.Content.ReadAsByteArrayAsync();

            var routing = AmqpCommunication.ResourceRequestQueue;

            _log.LogTrace("Response. exchange: {exchange} route: {queue}", baseUri.Host, routing);
            if (options.CancellationToken.IsCancellationRequested)
            {
                return;
            }

            await _communication.Send(baseUri.Host, routing, new BasicDeliverEventArgs { Body = body, BasicProperties = props });
        }
Example #2
0
        internal async Task SendResponse(BasicDeliverEventArgs request, HttpResponse response)
        {
            var requestProps   = request.BasicProperties;
            var replyToAdrress = requestProps.ReplyToAddress;

            if (replyToAdrress == null)
            {
                _log.LogInformation($"Request {requestProps.MessageId} ReplyToAddress is empty. Response not be sent");
                return;
            }

            var props = _communication.Channel.CreateBasicProperties().CreateBasicPropertiesResponse(requestProps, response);

            props.AppId = _option.ServerName.Host;
            var body = await response.Body.ReadAllBytesAsync();

            var routing = replyToAdrress.RoutingKey;

            _log.LogTrace("Response. exchange: {exchange} route: {queue}", replyToAdrress.ExchangeName, replyToAdrress.RoutingKey);

            try
            {
                await _communication.Send(replyToAdrress.ExchangeName, routing, new BasicDeliverEventArgs { Body = body, BasicProperties = props });
            }
            catch (Exception e)
            {
                _log.LogError(e, "Ошибка при отправке сообщения");
            }
            _log.LogTrace("Response. exchange: {exchange} route: {queue} sended", replyToAdrress.ExchangeName, routing);
        }