private async Task QueueListener_RequestReceived(object sender, RequestReceivedEventArgs e) { var iMessages = Counters.IncrementMessages(); try { Counters.IncrementReceivingTime(e.Request.Header.TotalTime); if (_serverQueues?.AdditionalSendQueues?.Any() == true) { e.ResponseQueues.AddRange(_serverQueues.AdditionalSendQueues); } e.Response.Header.Response.Label = Config.ResponseOptions.ServerSenderOptions.Label; Core.Log.InfoDetail("Request message received with CorrelationId = {0} . Current messages processing = {1}", e.Request.CorrelationId, iMessages); if (RequestReceived != null) { await RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } e.Response.Header.Response.Label = string.IsNullOrEmpty(e.Response.Header.Response.Label) ? e.Response.Body?.ToString() ?? typeof(ResponseMessage).FullName : e.Response.Header.Response.Label; if (MQueueServerEvents.RequestReceived != null) { await MQueueServerEvents.RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (e.SendResponse && e.Response?.Body != ResponseMessage.NoResponse) { e.Response.Header.Response.ApplicationSentDate = Core.Now; ResponseSentEventArgs rsea = null; if (BeforeSendResponse != null || MQueueServerEvents.BeforeSendResponse != null || ResponseSent != null || MQueueServerEvents.ResponseSent != null) { rsea = new ResponseSentEventArgs(Name, e.Response); if (BeforeSendResponse != null) { await BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueServerEvents.BeforeSendResponse != null) { await MQueueServerEvents.BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } } var sentBytes = await OnSendAsync(e.Response, e).ConfigureAwait(false); if (sentBytes > -1) { if (rsea != null) { rsea.MessageLength = sentBytes; if (ResponseSent != null) { await ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueServerEvents.ResponseSent != null) { await MQueueServerEvents.ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } } } else { Core.Log.Warning("The message couldn't be sent."); } } Counters.DecrementMessages(); Counters.IncrementTotalMessagesProccesed(); } catch (Exception) { Counters.IncrementTotalExceptions(); Counters.DecrementMessages(); throw; } }
private async Task QueueListener_RequestReceived(object sender, RawRequestReceivedEventArgs e) { var iMessages = Counters.IncrementMessages(); try { if (_serverQueues?.AdditionalSendQueues?.Any() == true) { e.ResponseQueues.AddRange(_serverQueues.AdditionalSendQueues); } Counters.IncrementTotalReceivingBytes(e.MessageLength); Core.Log.InfoDetail("Request message received with CorrelationId = {0} . Current messages processing = {1}", e.CorrelationId, iMessages); if (RequestReceived != null) { await RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (MQueueRawServerEvents.RequestReceived != null) { await MQueueRawServerEvents.RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (e.SendResponse && e.Response != null) { var response = e.Response; RawResponseSentEventArgs rsea = null; if (BeforeSendResponse != null || MQueueRawServerEvents.BeforeSendResponse != null || ResponseSent != null || MQueueRawServerEvents.ResponseSent != null) { rsea = new RawResponseSentEventArgs(Name, response, e.CorrelationId); if (BeforeSendResponse != null) { await BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueRawServerEvents.BeforeSendResponse != null) { await MQueueRawServerEvents.BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } } response = rsea?.Message ?? e.Response; var sentBytes = await OnSendAsync(response, e).ConfigureAwait(false); if (sentBytes > -1) { if (rsea != null) { rsea.MessageLength = sentBytes; if (ResponseSent != null) { await ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueRawServerEvents.ResponseSent != null) { await MQueueRawServerEvents.ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } } } else { Core.Log.Warning("The message couldn't be sent."); } } Counters.DecrementMessages(); Counters.IncrementTotalMessagesProccesed(); } catch (Exception) { Counters.IncrementTotalExceptions(); Counters.DecrementMessages(); throw; } }
private async Task QueueListener_RequestReceived(object sender, RequestReceivedEventArgs e) { var iMessages = Counters.IncrementMessages(); try { Counters.IncrementReceivingTime(e.Request.Header.TotalTime); Counters.IncrementTotalReceivingBytes(e.MessageLength); if (_serverQueues?.AdditionalSendQueues?.Any() == true) { e.ResponseQueues.AddRange(_serverQueues.AdditionalSendQueues); } #region Client Queues Routes Rebindings if (_serverQueues?.ClientQueuesRoutesRebindings != null) { Core.Log.LibDebug("Processing ClientQueues Route Rebinding"); foreach (var queue in e.ResponseQueues) { if (queue.IsSkippingRoute()) { continue; } if (_serverQueues.ClientQueuesRoutesRebindings.TryGet(queue.Route, out var qRebinding)) { Core.Log.LibVerbose("Rebinding Route: '{0}' to '{1}'", queue.Route, qRebinding.Value); queue.Route = qRebinding.Value; } else { Core.Log.LibVerbose("Route '{0}' doesn't have a Rebinding.", queue.Route); } } } #endregion e.Response.Header.Response.Label = Config.ResponseOptions.ServerSenderOptions.Label; Core.Log.LibDebug("Request message received with CorrelationId = {0} . Current messages processing = {1}", e.Request.CorrelationId, iMessages); if (RequestReceived != null) { await RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } e.Response.Header.Response.Label = string.IsNullOrEmpty(e.Response.Header.Response.Label) ? ResponseMessageFullName : e.Response.Header.Response.Label; if (MQueueServerEvents.RequestReceived != null) { await MQueueServerEvents.RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (e.SendResponse && e.Response != null && e.Response.Body != ResponseMessage.NoResponseSerialized) { e.Response.Header.Response.ApplicationSentDate = Core.Now; ResponseSentEventArgs rsea = null; if (BeforeSendResponse != null || MQueueServerEvents.BeforeSendResponse != null || ResponseSent != null || MQueueServerEvents.ResponseSent != null) { rsea = new ResponseSentEventArgs(Name, e.Response); Task t1 = null, t2 = null; if (BeforeSendResponse != null) { t1 = BeforeSendResponse.InvokeAsync(this, rsea); } if (MQueueServerEvents.BeforeSendResponse != null) { t2 = MQueueServerEvents.BeforeSendResponse.InvokeAsync(this, rsea); } if (t1 != null) { await t1.ConfigureAwait(false); } if (t2 != null) { await t2.ConfigureAwait(false); } } var sentBytes = await OnSendAsync(e.Response, e).ConfigureAwait(false); if (sentBytes > -1) { if (rsea != null) { rsea.MessageLength = sentBytes; Task t1 = null, t2 = null; if (ResponseSent != null) { t1 = ResponseSent.InvokeAsync(this, rsea); } if (MQueueServerEvents.ResponseSent != null) { t2 = MQueueServerEvents.ResponseSent.InvokeAsync(this, rsea); } if (t1 != null) { await t1.ConfigureAwait(false); } if (t2 != null) { await t2.ConfigureAwait(false); } } } else { Core.Log.Warning("The message couldn't be sent."); } } Counters.DecrementMessages(); Counters.IncrementTotalMessagesProccesed(); } catch (Exception) { Counters.IncrementTotalExceptions(); Counters.DecrementMessages(); throw; } }
protected Task OnRequestReceivedAsync(RawRequestReceivedEventArgs requestReceived) => RequestReceived?.InvokeAsync(this, requestReceived) ?? Task.CompletedTask;
private async Task QueueListener_RequestReceived(object sender, RawRequestReceivedEventArgs e) { var iMessages = Counters.IncrementMessages(); try { if (_serverQueues?.AdditionalSendQueues?.Any() == true) { e.ResponseQueues.AddRange(_serverQueues.AdditionalSendQueues); } #region Client Queues Routes Rebindings if (_serverQueues.ClientQueuesRoutesRebindings != null) { Core.Log.LibDebug("Processing ClientQueues Route Rebinding"); foreach (var queue in e.ResponseQueues) { if (queue.IsSkippingRoute()) { continue; } if (_serverQueues.ClientQueuesRoutesRebindings.TryGet(queue.Route, out var qRebinding)) { Core.Log.LibVerbose("Rebinding Route: '{0}' to '{1}'", queue.Route, qRebinding.Value); queue.Route = qRebinding.Value; } else { Core.Log.LibVerbose("Route '{0}' doesn't have a Rebinding.", queue.Route); } } } #endregion Counters.IncrementTotalReceivingBytes(e.MessageLength); Core.Log.LibDebug("Request message received with CorrelationId = {0} . Current messages processing = {1}", e.CorrelationId, iMessages); if (RequestReceived != null) { await RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (MQueueRawServerEvents.RequestReceived != null) { await MQueueRawServerEvents.RequestReceived.InvokeAsync(sender, e).ConfigureAwait(false); } if (e.SendResponse && e.Response != MultiArray <byte> .Empty) { var response = e.Response; RawResponseSentEventArgs rsea = null; if (BeforeSendResponse != null || MQueueRawServerEvents.BeforeSendResponse != null || ResponseSent != null || MQueueRawServerEvents.ResponseSent != null) { rsea = new RawResponseSentEventArgs(Name, response, e.CorrelationId); if (BeforeSendResponse != null) { await BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueRawServerEvents.BeforeSendResponse != null) { await MQueueRawServerEvents.BeforeSendResponse.InvokeAsync(this, rsea).ConfigureAwait(false); } } response = rsea?.Message ?? e.Response; var sentBytes = await OnSendAsync(response, e).ConfigureAwait(false); if (sentBytes > -1) { if (rsea != null) { rsea.MessageLength = sentBytes; if (ResponseSent != null) { await ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } if (MQueueRawServerEvents.ResponseSent != null) { await MQueueRawServerEvents.ResponseSent.InvokeAsync(this, rsea).ConfigureAwait(false); } } } else { Core.Log.Warning("The message couldn't be sent."); } } Counters.DecrementMessages(); Counters.IncrementTotalMessagesProccesed(); } catch (Exception) { Counters.IncrementTotalExceptions(); Counters.DecrementMessages(); throw; } }