Exemplo n.º 1
0
        public async Task <Guid> SendAsync <T>(T obj, Guid correlationId)
        {
            var rqMsg = obj as RequestMessage ?? new RequestMessage(obj)
            {
                Header =
                {
                    CorrelationId       = correlationId,
                    ApplicationSentDate = Core.Now,
                    MachineName         = Core.MachineName,
                    Label      = Config?.RequestOptions?.ClientSenderOptions?.Label ?? obj?.GetType().FullName,
                    ClientName = Config?.Name
                }
            };
            RequestSentEventArgs rsea = null;

            if (OnBeforeSendRequest != null || MQueueClientEvents.OnBeforeSendRequest != null ||
                OnRequestSent != null || MQueueClientEvents.OnRequestSent != null)
            {
                rsea = new RequestSentEventArgs(Name, rqMsg);
                if (OnBeforeSendRequest != null)
                {
                    await OnBeforeSendRequest.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
                if (MQueueClientEvents.OnBeforeSendRequest != null)
                {
                    await MQueueClientEvents.OnBeforeSendRequest.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
            }

            if (!await OnSendAsync(rqMsg).ConfigureAwait(false))
            {
                return(Guid.Empty);
            }
            Counters.IncrementMessagesSent();

            if (rsea != null)
            {
                if (OnRequestSent != null)
                {
                    await OnRequestSent.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
                if (MQueueClientEvents.OnRequestSent != null)
                {
                    await MQueueClientEvents.OnRequestSent.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
            }

            return(rqMsg.CorrelationId);
        }
Exemplo n.º 2
0
        public async Task <Guid> SendAsync <T>(T obj, Guid correlationId)
        {
            bool           disposeRequest = false;
            RequestMessage rqMsg          = null;

            if (obj is RequestMessage rmsg)
            {
                rqMsg = rmsg;
            }
            else
            {
                rqMsg = new RequestMessage(SenderSerializer.GetSerializedObject(obj))
                {
                    Header =
                    {
                        CorrelationId       = correlationId,
                        ApplicationSentDate = Core.Now,
                        MachineName         = Core.MachineName,
                        Label      = Config?.RequestOptions?.ClientSenderOptions?.Label ?? obj?.GetType().FullName,
                        ClientName = Config?.Name
                    }
                };
                disposeRequest = true;
            }
            RequestSentEventArgs rsea = null;

            if (OnBeforeSendRequest != null || MQueueClientEvents.OnBeforeSendRequest != null ||
                OnRequestSent != null || MQueueClientEvents.OnRequestSent != null)
            {
                rsea = new RequestSentEventArgs(Name, rqMsg);
                if (OnBeforeSendRequest != null)
                {
                    await OnBeforeSendRequest.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
                if (MQueueClientEvents.OnBeforeSendRequest != null)
                {
                    await MQueueClientEvents.OnBeforeSendRequest.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
            }

            if (!await OnSendAsync(rqMsg).ConfigureAwait(false))
            {
                if (disposeRequest)
                {
                    rqMsg.Body?.Dispose();
                    rqMsg.Body = null;
                }
                return(Guid.Empty);
            }
            Counters.IncrementMessagesSent();

            if (rsea != null)
            {
                if (OnRequestSent != null)
                {
                    disposeRequest = false;
                    await OnRequestSent.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
                if (MQueueClientEvents.OnRequestSent != null)
                {
                    disposeRequest = false;
                    await MQueueClientEvents.OnRequestSent.InvokeAsync(this, rsea).ConfigureAwait(false);
                }
            }

            if (disposeRequest)
            {
                rqMsg.Body?.Dispose();
                rqMsg.Body = null;
            }
            return(rqMsg.CorrelationId);
        }