public override async Task <List <TransmissionPayload> > MessagesPull(int?count, int?wait, string mappingChannel = null)
        {
            var list = new List <TransmissionPayload>();

            int countDown = count ?? 1;

            TransmissionPayload payload;

            Guid?batchId = null;

            if (BoundaryLoggingActive)
            {
                batchId = Collector?.BoundaryBatchPoll(count ?? -1, mPending.Count, mappingChannel ?? ChannelId, Priority);
            }

            while (countDown > 0 && mPending.TryDequeue(out payload))
            {
                if (mappingChannel != null)
                {
                    payload.Message.ChannelId = mappingChannel;
                }

                //Get the boundary logger to log the metadata.
                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Incoming, payload, ChannelId, Priority, batchId: batchId);
                }

                list.Add(payload);

                countDown--;
            }

            return(list);
        }
示例#2
0
        /// <summary>
        /// This method invokes the event to simulate transmission of the payload.
        /// </summary>
        /// <param name="payload">The payload to transmit.</param>
        /// <param name="retry">The retry count.</param>
        /// <returns></returns>
        public override async Task Transmit(TransmissionPayload payload, int retry = 0)
        {
            bool tryAgain = false;
            bool fail     = true;

            try
            {
                LastTickCount = Environment.TickCount;

                if (retry > MaxRetries)
                {
                    throw new RetryExceededTransmissionException();
                }

                IncomingAction?.Invoke(payload);

                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority);
                }

                fail = false;
            }
            catch (Exception ex)
            {
                LogException("Unhandled Exception (Transmit)", ex);
                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority, ex);
                }
                throw;
            }
            finally
            {
                if (fail)
                {
                    StatisticsInternal.ExceptionHitIncrement();
                }
            }

            if (tryAgain)
            {
                await Transmit(payload, ++retry);
            }
        }
示例#3
0
        /// <summary>
        /// This method wraps the incoming fabric message in to a generic payload.
        /// </summary>
        /// <param name="message">The incoming fabric message.</param>
        /// <param name="priority">The message priority.</param>
        /// <param name="mappingChannel">The mapping channel.</param>
        /// <param name="batchId">The current batch id.</param>
        /// <returns>Returns the payload with the service message.</returns>
        protected virtual TransmissionPayload TransmissionPayloadUnpack(M message, int priority, string mappingChannel = null, Guid?batchId = null)
        {
            ServiceMessage serviceMessage = MessageUnpack(message);

            serviceMessage.ChannelPriority = priority;

            if (mappingChannel != null)
            {
                serviceMessage.ChannelId = mappingChannel;
            }

            //Get the payload message with the associated metadata for transmission
            var payload = PayloadRegisterAndCreate(message, serviceMessage);

            //Get the boundary logger to log the metadata.
            if (BoundaryLoggingActive)
            {
                Collector?.BoundaryLog(ChannelDirection.Incoming, payload, ChannelId, Priority, batchId: batchId);
            }

            return(payload);
        }
示例#4
0
        /// <summary>
        /// This method will transmit a message.
        /// </summary>
        /// <param name="message">The message to transmit.</param>
        /// <param name="retry">The current number of retries.</param>
        public override async Task Transmit(TransmissionPayload payload, int retry = 0)
        {
            bool tryAgain = false;
            bool fail     = true;

            try
            {
                LastTickCount = Environment.TickCount;

                if (retry > MaxRetries)
                {
                    throw new RetryExceededTransmissionException();
                }

                var message = MessagePack(payload);
                await MessageTransmit(message);

                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority);
                }
                fail = false;
            }
            catch (NoMatchingSubscriptionException nex)
            {
                //OK, this happens when the remote transmitting party has closed or recycled.
                LogException($"The sender has closed: {payload.Message.CorrelationServiceId}", nex);
                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority, nex);
                }
            }
            catch (TimeoutException tex)
            {
                LogException("TimeoutException (Transmit)", tex);
                tryAgain = true;
                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority, tex);
                }
            }
            catch (MessagingException dex)
            {
                //OK, something has gone wrong with the Azure fabric.
                LogException("Messaging Exception (Transmit)", dex);
                //Let's reinitialise the client
                if (ClientReset == null)
                {
                    throw;
                }

                ClientReset(dex);
                tryAgain = true;
            }
            catch (Exception ex)
            {
                LogException("Unhandled Exception (Transmit)", ex);
                if (BoundaryLoggingActive)
                {
                    Collector?.BoundaryLog(ChannelDirection.Outgoing, payload, ChannelId, Priority, ex);
                }
                throw;
            }
            finally
            {
                if (fail)
                {
                    StatisticsInternal.ExceptionHitIncrement();
                }
            }

            if (tryAgain)
            {
                await Transmit(payload, ++retry);
            }
        }