private async Task SendResponseMessage(QueueBasedApiContext context) { context.ProcessingStopwatch.Stop(); string correlationId = context.BrokerProperties.GetNamedString("CorrelationId", string.Empty); string clientEtag = context.Request.GetNamedString("ETag", string.Empty); var brokerProperties = new JsonObject(); brokerProperties.SetNamedString("CorrelationId", correlationId); var message = new JsonObject(); message.SetNamedString("ResultCode", context.ResultCode.ToString()); message.SetNamedNumber("ProcessingDuration", context.ProcessingStopwatch.ElapsedMilliseconds); if (context.CallType == ApiCallType.Request) { string serverEtag = context.Response.GetNamedObject("Meta", new JsonObject()).GetNamedString("Hash", string.Empty); message.SetNamedString("ETag", serverEtag); if (!string.Equals(clientEtag, serverEtag)) { message.SetNamedValue("Content", context.Response); } } else { message.SetNamedValue("Content", context.Response); } await _outboundQueue.SendAsync(brokerProperties, message); }
private void DistpachMessage(object sender, MessageReceivedEventArgs e) { Stopwatch processingStopwatch = Stopwatch.StartNew(); string uri = e.Body.GetNamedString("Uri", string.Empty); if (string.IsNullOrEmpty(uri)) { Log.Warning("Received Azure queue message with missing or invalid URI property."); return; } string callTypeSource = e.Body.GetNamedString("CallType", string.Empty); ApiCallType callType; if (!Enum.TryParse(callTypeSource, true, out callType)) { Log.Warning("Received Azure queue message with missing or invalid CallType property."); return; } var request = e.Body.GetNamedObject("Content", new JsonObject()); var context = new QueueBasedApiContext(e.BrokerProperties, e.Body, processingStopwatch, callType, uri, request, new JsonObject()); var eventArgs = new ApiRequestReceivedEventArgs(context); RequestReceived?.Invoke(this, eventArgs); if (!eventArgs.IsHandled) { Log.Warning("Received Azure queue message is not handled."); Log.Warning("Received Azure queue message is not handled."); return; } SendResponseMessage(context).Wait(); }