Ejemplo 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);
        }
Ejemplo n.º 2
0
        public async Task <Guid> SendBytesAsync(byte[] obj, Guid correlationId)
        {
            RawMessageEventArgs rmea = null;

            if (OnBeforeSendRequest != null || MQueueRawClientEvents.OnBeforeSendRequest != null ||
                OnRequestSent != null || MQueueRawClientEvents.OnRequestSent != null)
            {
                rmea = new RawMessageEventArgs(Name, obj);
                if (OnBeforeSendRequest != null)
                {
                    await OnBeforeSendRequest.InvokeAsync(this, rmea).ConfigureAwait(false);
                }
                if (MQueueRawClientEvents.OnBeforeSendRequest != null)
                {
                    await MQueueRawClientEvents.OnBeforeSendRequest.InvokeAsync(this, rmea).ConfigureAwait(false);
                }
                obj = rmea.Message;
            }
            if (!await OnSendAsync(obj, correlationId).ConfigureAwait(false))
            {
                return(Guid.Empty);
            }
            Counters.IncrementMessagesSent();
            Counters.IncrementTotalBytesSent(obj.Length);
            if (rmea != null)
            {
                if (OnRequestSent != null)
                {
                    await OnRequestSent.InvokeAsync(this, rmea).ConfigureAwait(false);
                }
                if (MQueueRawClientEvents.OnRequestSent != null)
                {
                    await MQueueRawClientEvents.OnRequestSent.InvokeAsync(this, rmea).ConfigureAwait(false);
                }
            }
            return(correlationId);
        }
Ejemplo n.º 3
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);
        }