/// <summary> /// This method marshals the RepositoryHolder and transmits it to the remote Microservice. /// </summary> /// <typeparam Name="KT">The key type.</typeparam> /// <typeparam Name="ET">The entity type.</typeparam> /// <param name="actionType">The action type.</param> /// <param name="rq">The repository holder request.</param> /// <param name="routing"></param> /// <returns>Returns an async task that will be signalled when the request completes or times out.</returns> protected override async Task <RepositoryHolder <KT, ET> > TransmitInternal <KT, ET>(string actionType, RepositoryHolder <KT, ET> rq, ProcessOptions?routing = null, IPrincipal principal = null) { StatisticsInternal.ActiveIncrement(); var payloadRq = TransmissionPayload.Create(mPolicy.TransmissionPayloadTraceEnabled); // Set the originator key to the correlation id if passed through the rq settings if (!string.IsNullOrEmpty(rq.Settings?.CorrelationId)) { payloadRq.Message.ProcessCorrelationKey = rq.Settings.CorrelationId; } bool processAsync = rq.Settings?.ProcessAsync ?? false; payloadRq.Options = ProcessOptions.RouteInternal; var message = payloadRq.Message; payloadRq.MaxProcessingTime = rq.Settings?.WaitTime ?? mDefaultRequestTimespan; payloadRq.MessageObject = rq; message.ChannelId = ChannelId; message.ChannelPriority = processAsync ? 0:-1; message.MessageType = mMessageType; message.ActionType = actionType; message.ResponseChannelId = mResponseChannel; message.ResponseChannelPriority = -1; //Always internal message.Blob = PayloadSerializer.PayloadSerialize(rq); return(await OutgoingRequestOut(payloadRq, ProcessResponse <KT, ET>, processAsync : processAsync)); }
/// <summary> /// This method marshals the RepositoryHolder and transmits it to the remote Microservice. /// </summary> /// <typeparam Name="KT">The key type.</typeparam> /// <typeparam Name="ET">The entity type.</typeparam> /// <param name="actionType">The action type.</param> /// <param name="rq">The repository holder request.</param> /// <param name="routing"></param> /// <returns>Returns an async task that will be signalled when the request completes or times out.</returns> protected override async Task <RepositoryHolder <KT, ET> > TransmitInternal <KT, ET>(string actionType, RepositoryHolder <KT, ET> rq, ProcessOptions?routing = null) { StatisticsInternal.ActiveIncrement(); var payloadRq = TransmissionPayload.Create(); bool processAsync = rq.Settings?.ProcessAsync ?? false; payloadRq.Options = ProcessOptions.RouteInternal; var message = payloadRq.Message; payloadRq.MaxProcessingTime = rq.Settings?.WaitTime ?? mDefaultRequestTimespan; payloadRq.MessageObject = rq; message.ChannelId = ChannelId; message.ChannelPriority = processAsync ? 0:-1; message.MessageType = mMessageType; message.ActionType = actionType; message.ResponseChannelId = mResponseChannel; message.ResponseChannelPriority = -1; //Always internal message.Blob = PayloadSerializer.PayloadSerialize(rq); return(await TransmitAsync(payloadRq, ProcessResponse <KT, ET>, processAsync : processAsync)); }
/// <summary> /// This method marshals the RepositoryHolder and transmits it to the remote Microservice. /// </summary> /// <typeparam Name="KT">The key type.</typeparam> /// <typeparam Name="ET">The entity type.</typeparam> /// <param Name="actionType">The action type.</param> /// <param Name="rq">The repository holder request.</param> /// <returns>Returns an async task that will be signalled when the request completes or times out.</returns> protected override async Task <RepositoryHolder <KT, ET> > TransmitInternal <KT, ET>( string actionType, RepositoryHolder <KT, ET> rq, ProcessOptions?routing = null, IPrincipal principal = null) { try { StatisticsInternal.ActiveIncrement(); var payload = TransmissionPayload.Create(Policy.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(rq.Settings?.CorrelationId)) { payload.Message.ProcessCorrelationKey = rq.Settings.CorrelationId; } bool processAsync = rq.Settings?.ProcessAsync ?? false; payload.Message.ChannelPriority = processAsync ? 0 : 1; payload.Options = routing ?? RoutingDefault ?? ProcessOptions.RouteExternal; payload.Message.Blob = PayloadSerializer.PayloadSerialize(rq); payload.Message.ResponseChannelId = ResponseChannelId; payload.Message.ResponseChannelId = ResponseId.Header.ChannelId; payload.Message.ResponseMessageType = ResponseId.Header.MessageType; payload.Message.ResponseActionType = ResponseId.Header.ActionType; payload.Message.ResponseChannelPriority = payload.Message.ChannelPriority; payload.Message.ChannelId = ChannelId; payload.Message.MessageType = EntityType; payload.Message.ActionType = actionType; payload.MaxProcessingTime = rq.Settings?.WaitTime ?? mDefaultRequestTimespan; return(await OutgoingRequestOut(payload, ProcessResponse <KT, ET>, processAsync)); } catch (Exception ex) { string key = rq != null && rq.Key != null?rq.Key.ToString() : string.Empty; Collector?.LogException($"Error transmitting {actionType}-{key} internally", ex); throw; } }
/// <summary> /// This method transmits the notification message to the other instances. /// The message is specified to be processed externally so to ensure that we can determine whether /// the comms are active. /// </summary> /// <param name="action">The action to transmit.</param> protected virtual async Task NegotiationTransmit(string action) { var payload = TransmissionPayload.Create(); payload.Options = ProcessOptions.RouteExternal; var message = payload.Message; //Note: historically there was only one channel, so we use the incoming channel if the outgoing has //not been specified. message.ChannelId = mPolicy.MasterJobNegotiationChannelIdOutgoing ?? mPolicy.MasterJobNegotiationChannelIdIncoming; message.ChannelPriority = mPolicy.MasterJobNegotiationChannelPriority; message.MessageType = mPolicy.MasterJobNegotiationChannelType; message.ActionType = action; //Go straight to the dispatcher as we don't want to use the tracker for this job //as it is transmit only. TaskManager(this, payload); }
/// <summary> /// This method marshals the RepositoryHolder and transmits it to the remote Microservice. /// </summary> /// <typeparam Name="KT">The key type.</typeparam> /// <typeparam Name="ET">The entity type.</typeparam> /// <param Name="actionType">The action type.</param> /// <param Name="rq">The repository holder request.</param> /// <returns>Returns an async task that will be signalled when the request completes or times out.</returns> protected override async Task <RepositoryHolder <KT, ET> > TransmitInternal <KT, ET>(string actionType, RepositoryHolder <KT, ET> rq, ProcessOptions?routing = null) { try { StatisticsInternal.ActiveIncrement(); var payload = TransmissionPayload.Create(); // Set the originator key to the correlation id if passed through the rq settings if (rq.Settings != null && !string.IsNullOrEmpty(rq.Settings.CorrelationId)) { payload.Message.OriginatorKey = rq.Settings.CorrelationId; } bool processAsync = rq.Settings == null ? false : rq.Settings.ProcessAsync; payload.Message.ChannelPriority = processAsync ? 0 : 1; payload.Options = routing ?? RoutingDefault ?? ProcessOptions.RouteExternal; payload.Message.Blob = PayloadSerializer.PayloadSerialize(rq); payload.Message.ResponseChannelId = ResponseChannelId; payload.Message.ResponseChannelPriority = payload.Message.ChannelPriority; payload.Message.ChannelId = ChannelId; payload.Message.MessageType = EntityType; payload.Message.ActionType = actionType; payload.MaxProcessingTime = rq.Settings?.WaitTime ?? mDefaultRequestTimespan; return(await TransmitAsync(payload, ProcessResponse <KT, ET>, processAsync)); } catch (Exception ex) { string key = rq != null && rq.Key != null?rq.Key.ToString() : string.Empty; Logger.LogException(string.Format("Error transmitting {0}-{1} internally", actionType, key), ex); throw; } }
public async Task Write <K, E>(string originatorId, EventSourceEntry <K, E> entry, DateTime?utcTimeStamp = default(DateTime?), bool sync = false) { try { var client = ClientResolve(1); var payload = TransmissionPayload.Create(); payload.Message.Blob.SetObject(entry); payload.Message.OriginatorServiceId = originatorId; if (utcTimeStamp.HasValue) { entry.UTCTimeStamp = utcTimeStamp.Value; } client.Transmit(payload); } catch (Exception ex) { LogExceptionLocation("Write EventSource (Unhandled)", ex); //OK, not sure what happened here, so we need to throw the exception. //throw ex; } }
/// <summary> /// This method transmits the notification message to the other instances. /// The message is specified to be processed externally so to ensure that we can determine whether /// the comms are active. /// </summary> /// <param name="action">The master job action to transmit.</param> protected virtual Task NegotiationTransmit(string action) { var payload = TransmissionPayload.Create(mPolicy.TransmissionPayloadTraceEnabled); payload.TraceWrite("Create", "Command/NegotiationTransmit"); payload.Options = ProcessOptions.RouteExternal; var message = payload.Message; //Note: historically there was only one channel, so we use the incoming channel if the outgoing has //not been specified. These should all be lower case so that Service Bus can match accurately. message.ChannelId = (mPolicy.MasterJobNegotiationChannelIdOutgoing ?? mPolicy.MasterJobNegotiationChannelIdIncoming).ToLowerInvariant(); message.MessageType = mPolicy.MasterJobNegotiationChannelType.ToLowerInvariant(); message.ActionType = action.ToLowerInvariant(); message.ChannelPriority = mPolicy.MasterJobNegotiationChannelPriority; //Go straight to the dispatcher as we don't want to use the tracker for this job //as it is transmit only. Only send messages if the service is in a running state. switch (Status) { case ServiceStatus.Running: case ServiceStatus.Stopping: TaskManager(this, null, payload); FireAndDecorateEventArgs(OnMasterJobCommunication , () => new MasterJobCommunicationEventArgs( MasterJobCommunicationDirection.Outgoing , mMasterJobContext.State , action , mMasterJobContext.StateChangeCounter) , (args, ex) => payload.TraceWrite($"Error: {ex.Message}", "Command/NegotiationTransmit/OnMasterJobCommunication")); break; } return(Task.FromResult(0)); }
/// <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 internal 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 (!Policy.OutgoingRequestsEnabled) { throw new OutgoingRequestsNotEnabledException(); } TransmissionPayload payload = null; try { StatisticsInternal.ActiveIncrement(); payload = TransmissionPayload.Create(Policy.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 ?? Policy.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; } }