protected abstract Task <int> OnSendAsync(ResponseMessage message, RequestReceivedEventArgs e);
protected Task OnRequestReceivedAsync(RequestReceivedEventArgs requestReceived) => RequestReceived?.InvokeAsync(this, requestReceived) ?? Task.CompletedTask;
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; } }