/// <summary> /// This method is used to send requests to the remote command. /// </summary> /// <typeparam name="I">The contract interface.</typeparam> /// <typeparam name="RQ">The request type.</typeparam> /// <typeparam name="RS">The response type.</typeparam> /// <param name="rq">The request object.</param> /// <param name="rqSettings">The request settings. Use this to specifically set the timeout parameters.</param> /// <param name="routingOptions">The routing options by default this will try internal and then external.</param> /// <param name="processResponse"></param> /// <param name="fallbackMaxProcessingTime">This is the fallback max processing time used if the timeout /// is not set in the request settings. /// If this is also null, the max time out will fall back to the policy settings.</param> /// <param name="principal">This is the principal that you wish the command to be executed under. /// By default this is taken from the calling thread if not passed.</param> /// <returns>Returns the async response wrapper.</returns> /// <returns>Returns a response object of the specified type in a response metadata wrapper.</returns> protected virtual async Task <ResponseWrapper <RS> > ProcessOutgoing <I, RQ, RS>(RQ rq , RequestSettings rqSettings = null , ProcessOptions?routingOptions = null , Func <TaskStatus, TransmissionPayload, bool, ResponseWrapper <RS> > processResponse = null , TimeSpan?fallbackMaxProcessingTime = null , IPrincipal principal = null) where I : IMessageContract { string channelId, messageType, actionType; if (!ServiceMessageHelper.ExtractContractInfo <I>(out channelId, out messageType, out actionType)) { throw new InvalidOperationException("Unable to locate message contract attributes for " + typeof(I)); } return(await ProcessOutgoing <RQ, RS>(channelId, messageType, actionType , rq , rqSettings , routingOptions , processResponse , fallbackMaxProcessingTime , principal ?? Thread.CurrentPrincipal )); }
/// <summary> /// This method is used to send requests to the remote command. /// </summary> /// <typeparam name="RQ">The request type.</typeparam> /// <typeparam name="RS">The response type.</typeparam> /// <param name="channelId">The header routing information.</param> /// <param name="messageType">The header routing information.</param> /// <param name="actionType">The header routing information.</param> /// <param name="rq">The request object.</param> /// <param name="rqSettings">The request settings. Use this to specifically set the timeout parameters.</param> /// <param name="routingOptions">The routing options by default this will try internal and then external.</param> /// <param name="processResponse"></param> /// <param name="fallbackMaxProcessingTime">This is the fallback max processing time used if the timeout /// is not set in the request settings. /// If this is also null, the max time out will fall back to the policy settings.</param> /// <param name="principal">This is the principal that you wish the command to be executed under. /// By default this is taken from the calling thread if not passed.</param> /// <returns>Returns the async response wrapper.</returns> protected virtual async Task <ResponseWrapper <RS> > ProcessOutgoing <RQ, RS>( string channelId, string messageType, string actionType , RQ rq , RequestSettings rqSettings = null , ProcessOptions?routingOptions = null , Func <TaskStatus, TransmissionPayload, bool, ResponseWrapper <RS> > processResponse = null , TimeSpan?fallbackMaxProcessingTime = null , IPrincipal principal = null ) { if (!mPolicy.OutgoingRequestsEnabled) { throw new OutgoingRequestsNotEnabledException(); } TransmissionPayload payload = null; try { StatisticsInternal.ActiveIncrement(); payload = TransmissionPayload.Create(mPolicy.TransmissionPayloadTraceEnabled); payload.SecurityPrincipal = TransmissionPayload.ConvertToClaimsPrincipal(principal ?? Thread.CurrentPrincipal); // Set the process correlation key to the correlation id if passed through the rq settings if (!string.IsNullOrEmpty(rqSettings?.CorrelationId)) { payload.Message.ProcessCorrelationKey = rqSettings.CorrelationId; } bool processAsync = rqSettings?.ProcessAsync ?? false; payload.Options = routingOptions ?? ProcessOptions.RouteExternal | ProcessOptions.RouteInternal; //Set the destination message payload.Message.ChannelId = channelId ?? ChannelId; payload.Message.MessageType = messageType; payload.Message.ActionType = actionType; payload.Message.ChannelPriority = processAsync ? 0 : 1; //Set the response path payload.Message.ResponseChannelId = ResponseId.Header.ChannelId; payload.Message.ResponseMessageType = ResponseId.Header.MessageType; payload.Message.ResponseActionType = ResponseId.Header.ActionType; payload.Message.ResponseChannelPriority = payload.Message.ChannelPriority; //Set the payload payload.Message.Blob = PayloadSerializer.PayloadSerialize(rq); //Set the processing time payload.MaxProcessingTime = rqSettings?.WaitTime ?? fallbackMaxProcessingTime ?? mPolicy.OutgoingRequestMaxProcessingTimeDefault; //Transmit return(await OutgoingRequestOut(payload, processResponse ?? ProcessOutgoingResponse <RS>, processAsync)); } catch (Exception ex) { string key = payload?.Id.ToString() ?? string.Empty; Collector?.LogException(string.Format("Error transmitting {0}-{1} internally", actionType, key), ex); throw; } }
/// <summary> /// This method is used to send requests to the remote command. /// </summary> /// <typeparam name="I">The contract interface.</typeparam> /// <typeparam name="RQ">The request type.</typeparam> /// <typeparam name="RS">The response type.</typeparam> /// <param name="rq">The request object.</param> /// <param name="routing"></param> /// <param name="settings"></param> /// <returns>Returns a response object of the specified type in a response metadata wrapper.</returns> protected virtual async Task <ResponseWrapper <RS> > ProcessOutgoing <I, RQ, RS>(RQ rq , RequestSettings settings = null , ProcessOptions?routing = null , IPrincipal principal = null) where I : IMessageContract { string channelId, messageType, actionType; if (!ServiceMessageHelper.ExtractContractInfo <I>(out channelId, out messageType, out actionType)) { throw new InvalidOperationException("Unable to locate message contract attributes for " + typeof(I)); } return(await ProcessOutgoing <RQ, RS>(channelId, messageType, actionType, rq, settings, routing , principal : principal ?? Thread.CurrentPrincipal)); }