コード例 #1
0
        /// <summary>
        /// This method processes the returning messages.
        /// </summary>
        /// <param name="payload">The incoming payload.</param>
        /// <param name="responses">The responses collection is not currently used.</param>
        protected virtual Task OutgoingRequestResponseIn(TransmissionPayload payload, List <TransmissionPayload> responses)
        {
            try
            {
                string id = payload?.Message?.CorrelationKey?.ToUpperInvariant();

                //Get the original request.
                OutgoingRequestTracker holder;
                if (id == null || !mOutgoingRequests.TryRemove(id, out holder))
                {
                    //If there is not a match key then quit.
                    Collector?.LogMessage(LoggingLevel.Warning, $"OutgoingRequestResponseIn - id {id ?? "is null"} not matched for {payload?.Message?.ProcessCorrelationKey}", "RqRsMismatch");
                    payload.SignalSuccess();
                    return(Task.FromResult(0));
                }

                holder.Tcs.SetResult(payload);

                FireAndDecorateEventArgs(OnOutgoingRequestComplete, () => new OutgoingRequestEventArgs(holder));
            }
            catch (Exception ex)
            {
                Collector?.LogException("OutgoingRequestResponseIn unexpected exception", ex);
            }
            finally
            {
                //Signal to the listener to release the message.
                payload?.SignalSuccess();
            }

            return(Task.FromResult(0));
        }
コード例 #2
0
        /// <summary>
        /// This method processes the returning messages.
        /// </summary>
        /// <param name="payload">The incoming payload.</param>
        /// <param name="responses">The responses collection is not currently used.</param>
        protected virtual async Task OutgoingRequestResponseProcess(TransmissionPayload payload, List <TransmissionPayload> responses)
        {
            string id = payload?.Message?.CorrelationKey?.ToUpperInvariant();;

            //If there is not a correlation key then quit.
            if (id == null)
            {
                Logger?.LogMessage(LoggingLevel.Warning, "OutgoingRequestsProcessResponse - id is null");
                return;
            }

            //This method signals the request as completed or failed and sets the incoming payload.
            if (!OutgoingRequestRemove(id, payload))
            {
                try
                {
                    OnTimedOutResponse?.Invoke(this, payload);
                }
                catch (Exception ex)
                {
                    Logger?.LogException("OnTimedOutResponse", ex);
                    //We do not want to throw exceptions here.
                }
            }

            //Signal to the listener to release the message.
            payload.SignalSuccess();
        }
コード例 #3
0
        private void Sender_OnProcess(object sender, TransmissionPayload e)
        {
            try
            {
                if (mActiveListeners.Length == 0)
                {
                    e.SignalSuccess();
                    return;
                }

                OnReceiveInvoke(sender, e);

                long count = Interlocked.Increment(ref mSendCount);

                switch (Mode)
                {
                case FabricMode.Queue:
                    Sender_TransmitRoundRobin(e, count);
                    break;

                case FabricMode.Broadcast:
                    Sender_TransmitBroadcast(e, count);
                    break;
                }
            }
            catch (Exception ex)
            {
                OnExceptionInvoke(sender, e, ex);
            }
        }
コード例 #4
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));
        }
コード例 #5
0
        /// <summary>
        /// This method injects a service message manually in to the Microservice.
        /// </summary>
        /// <param name="payload">The message payload.</param>
        /// <param name="priority">The optional priority. The default is 1.</param>
        public void Inject(TransmissionPayload payload, int?priority = null)
        {
            if (this.Status != ServiceStatus.Running)
            {
                payload.SignalSuccess();
                payload.TraceWrite($"Failed: {Status}", "ManualChannelListener/Inject");
                return;
            }

            try
            {
                var client = ClientResolve(priority ?? mDefaultPriority ?? 1);
                client.Inject(payload);
                payload.TraceWrite($"Success: {client.Name}", "ManualChannelListener/Inject");
            }
            catch (Exception ex)
            {
                payload.TraceWrite($"Error: {ex.Message}", "ManualChannelListener/Inject");
            }
        }