Пример #1
0
        /// <summary>
        /// This method processes an individual payload returned from a client.
        /// </summary>
        /// <param name="clientId">The originating client.</param>
        /// <param name="payload">The payload.</param>
        private void PayloadSubmit(Guid clientId, TransmissionPayload payload)
        {
            try
            {
                payload.TraceConfigure(mPolicy.TransmissionPayloadTraceEnabled);
                payload.TraceWrite("Incoming", "CommunicationContainer/PayloadSubmit");

                //Ensure the priority cannot spoof the internal priority of -1
                if (payload.Message.ChannelPriority < 0)
                {
                    payload.Message.ChannelPriority = 0;
                }

                mClientCollection.QueueTimeLog(clientId, payload.Message.EnqueuedTimeUTC);

                //Verify the incoming payload with the security container.
                PayloadIncomingSecurity(payload);

                //Do we need to redirect the payload based on the redirect/rewrite rules.
                PayloadIncomingRedirectCheck(payload);

                //Create the tracker to process the incoming
                TaskTracker tracker = TaskManager.TrackerCreateFromPayload(payload, payload.Source);

                //Set the function that executes when the payload completes.
                tracker.ExecuteComplete = (tr, failed, ex) =>
                {
                    var contextPayload = tr.ToTransmissionPayload();
                    try
                    {
                        mClientCollection.ActiveDecrement(clientId, tr.TickCount);

                        if (failed)
                        {
                            mClientCollection.ErrorIncrement(clientId);
                        }

                        contextPayload.Signal(!failed);

                        contextPayload.TraceWrite(failed?"Failed":"Success", "CommunicationContainer/PayloadSubmit -> ExecuteComplete");
                    }
                    catch (Exception exin)
                    {
                        Collector?.LogException($"Payload completion error-{payload} after {(tr.Context as TransmissionPayload)?.Message?.FabricDeliveryCount} delivery attempts", exin);
                        contextPayload.TraceWrite($"Exception: {ex.Message}", "CommunicationContainer/PayloadSubmit -> ExecuteComplete");
                    }
                };

                //Submit the tracker to the task manager.
                payload.TraceWrite("Outgoing", "CommunicationContainer/PayloadSubmit");

                TaskSubmit(tracker);
            }
            catch (Exception ex)
            {
                Collector?.LogException($"ProcessClientPayload: unhandled error {payload.Source}/{payload.Message.CorrelationKey}-{payload} after {payload.Message?.FabricDeliveryCount} delivery attempts", ex);
                payload.TraceWrite($"Exception: {ex.Message}", "CommunicationContainer/PayloadSubmit");
                payload.SignalFail();
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the exception.
        /// </summary>
        /// <param name="ex">The exception raised.</param>
        /// <param name="rq">The incoming request.</param>
        /// <param name="responses">The responses.</param>
        protected virtual Task ProcessRequestException(Exception ex, TransmissionPayload rq, List <TransmissionPayload> responses)
        {
            if (Policy.OnProcessRequestExceptionLog)
            {
                Collector?.LogException($"{FriendlyName}/ProcessRequest unhandled exception: {rq.Message.ToKey()}", ex);
            }

            switch (Policy.OnProcessRequestException)
            {
            case ProcessRequestExceptionBehaviour.DoNothing:
                break;

            case ProcessRequestExceptionBehaviour.SignalSuccessAndSend500ErrorResponse:
                rq.SignalSuccess();
                var rs = rq.ToResponse();
                rs.Message.Status            = "500";
                rs.Message.StatusDescription = ex.Message;
                responses.Add(rs);
                break;

            case ProcessRequestExceptionBehaviour.SignalFailAndDoNothing:
                rq.SignalFail();
                break;

            default:
                throw ex;
            }

            return(Task.FromResult(0));
        }
Пример #3
0
        /// <summary>
        /// Purges any remaining messages when the service shuts down.
        /// </summary>
        public void Purge()
        {
            TransmissionPayload payload = null;

            while (mPending?.TryDequeue(out payload) ?? false)
            {
                payload.TraceWrite("Purged", "ManualChannelClientHolder/Purge");
                payload.SignalFail();
            }
        }
        /// <summary>
        /// This method processes an individual payload returned from a client.
        /// </summary>
        /// <param name="clientId">The originating client.</param>
        /// <param name="payload">The payload.</param>
        private void PayloadSubmit(Guid clientId, TransmissionPayload payload)
        {
            try
            {
                if (payload.Message.ChannelPriority < 0)
                {
                    payload.Message.ChannelPriority = 0;
                }

                mClientCollection.QueueTimeLog(clientId, payload.Message.EnqueuedTimeUTC);
                mClientCollection.ActiveIncrement(clientId);

                //Verify the incoming payload with the security container.
                PayloadIncomingSecurity(payload);

                //Do we need to redirect the payload based on the redirect/rewrite rules.
                PayloadIncomingRedirectCheck(payload);

                TaskTracker tracker = TaskManager.TrackerCreateFromPayload(payload, payload.Source);

                tracker.ExecuteComplete = (tr, failed, ex) =>
                {
                    try
                    {
                        var contextPayload = tr.Context as TransmissionPayload;

                        mClientCollection.ActiveDecrement(clientId, tr.TickCount);

                        if (failed)
                        {
                            mClientCollection.ErrorIncrement(clientId);
                        }

                        contextPayload.Signal(!failed);
                    }
                    catch (Exception exin)
                    {
                        Collector?.LogException($"Payload completion error-{payload} after {(tr.Context as TransmissionPayload)?.Message?.FabricDeliveryCount} delivery attempts", exin);
                    }
                };

                //Submit the tracker to the task manager.
                TaskSubmit(tracker);
            }
            catch (Exception ex)
            {
                Collector?.LogException($"ProcessClientPayload: unhandled error {payload.Source}/{payload.Message.CorrelationKey}-{payload} after {payload.Message?.FabricDeliveryCount} delivery attempts", ex);
                payload.SignalFail();
            }
        }