Ejemplo n.º 1
0
        public async Task <byte[]> ReceiveBytesAsync(Guid correlationId, CancellationToken cancellationToken)
        {
            var bytes = await OnReceiveAsync(correlationId, cancellationToken).ConfigureAwait(false);

            if (bytes == null)
            {
                return(null);
            }

            Counters.IncrementMessagesReceived();
            Counters.IncrementTotalBytesReceived(bytes.Length);

            if (OnResponseReceived != null || MQueueRawClientEvents.OnResponseReceived != null)
            {
                var rrea = new RawMessageEventArgs(Name, bytes);
                if (OnResponseReceived != null)
                {
                    await OnResponseReceived.InvokeAsync(this, rrea).ConfigureAwait(false);
                }
                if (MQueueRawClientEvents.OnResponseReceived != null)
                {
                    await MQueueRawClientEvents.OnResponseReceived.InvokeAsync(this, rrea).ConfigureAwait(false);
                }
            }

            return(bytes);
        }
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);
        }