/// <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); }
/// <summary> /// This method packs the ServiceMessage in to the BrokeredMessage format /// for communication through the Azure Service Bus. /// </summary> /// <param name="sMessage">The ServiceMessage object to convert.</param> /// <returns>Returns a converted BrokeredMessage from transmission.</returns> public static EventData Pack(TransmissionPayload payload) { ServiceMessage sMessage = payload.Message; EventData bMessage; if (sMessage.Blob == null) { bMessage = new EventData(); } else { bMessage = new EventData(sMessage.Blob); } bMessage.Properties.Add("OriginatorKey", sMessage.OriginatorKey); bMessage.Properties.Add("OriginatorServiceId", sMessage.OriginatorServiceId); bMessage.Properties.Add("OriginatorUTC", sMessage.OriginatorUTC); bMessage.Properties.Add("ResponseChannelId", sMessage.ResponseChannelId); bMessage.Properties.Add("ChannelId", sMessage.ChannelId); bMessage.Properties.Add("MessageType", sMessage.MessageType); bMessage.Properties.Add("ActionType", sMessage.ActionType); bMessage.Properties.Add("IsNoop", sMessage.IsNoop ? "1" : "0"); bMessage.Properties.Add("IsReplay", sMessage.IsReplay ? "1" : "0"); bMessage.Properties.Add("CorrelationKey", sMessage.CorrelationKey); bMessage.Properties.Add("CorrelationServiceId", sMessage.CorrelationServiceId); bMessage.Properties.Add("CorrelationUTC", sMessage.CorrelationUTC.HasValue ? sMessage.CorrelationUTC.Value.ToString("o") : null); bMessage.Properties.Add("DispatcherTransitCount", sMessage.DispatcherTransitCount); bMessage.Properties.Add("Status", sMessage.Status); bMessage.Properties.Add("StatusDescription", sMessage.StatusDescription); return(bMessage); }
/// <summary> /// This method extracts the binary blob from the message and deserializes and returns the object. /// </summary> /// <param name="message">The service message.</param> /// <returns>Returns the object deserialized from the binary blob.</returns> public object PayloadDeserialize(ServiceMessage message) { try { if (message.Blob == null || mPayloadSerializers.Count == 0) { return(null); } var serializer = mPayloadSerializers.Values.FirstOrDefault(s => s.SupportsPayloadDeserialization(message.Blob)); if (serializer != null) { return(serializer.Deserialize(message.Blob)); } return(null); } catch (Exception ex) { throw new PayloadDeserializationException(message.OriginatorKey, ex); } }
/// <summary> /// This method unpacks the azure service bus message in to a generic ServiceMessage object /// which can be processed by the service.. /// /// </summary> /// <param name="bMessage">The Azure BrokeredMessage to convert.</param> /// <returns>Returns a generic ServiceMessage class for processing.</returns> public static ServiceMessage Unpack(EventData bMessage) { var sMessage = new ServiceMessage(); sMessage.OriginatorKey = bMessage.Properties["OriginatorKey"] as string; sMessage.OriginatorServiceId = bMessage.Properties["OriginatorServiceId"] as string; sMessage.OriginatorUTC = (DateTime)bMessage.Properties["OriginatorUTC"]; sMessage.ResponseChannelId = bMessage.Properties["ResponseChannelId"] as string; sMessage.ChannelId = bMessage.Properties["ChannelId"] as string; sMessage.MessageType = bMessage.Properties["MessageType"] as string; sMessage.ActionType = bMessage.Properties["ActionType"] as string; sMessage.IsNoop = bMessage.Properties["IsNoop"] as string == "1"; sMessage.IsReplay = bMessage.Properties["IsReplay"] as string == "1"; sMessage.CorrelationKey = bMessage.Properties["CorrelationKey"] as string; sMessage.CorrelationServiceId = bMessage.Properties["CorrelationServiceId"] as string; DateTime serviceUTC; if (bMessage.Properties.ContainsKey("CorrelationUTC") && DateTime.TryParse(bMessage.Properties["CorrelationUTC"] as string, out serviceUTC)) { sMessage.CorrelationUTC = serviceUTC; } sMessage.DispatcherTransitCount = (int)bMessage.Properties["DispatcherTransitCount"]; sMessage.Status = bMessage.Properties["Status"] as string; sMessage.StatusDescription = bMessage.Properties["StatusDescription"] as string; //sMessage.Blob = bMessage.GetBody<byte[]>(); return(sMessage); }
/// <summary> /// This method extracts the binary blob from the message and deserializes and returns the object. /// </summary> /// <typeparam name="P">The payload message type.</typeparam> /// <param name="srz">The serialization container.</param> /// <param name="message">The service message.</param> /// <returns>Returns the object deserialized from the binary blob.</returns> public static P PayloadDeserialize <P>(this IPayloadSerializationContainer srz, ServiceMessage message) { try { return(srz.PayloadDeserialize <P>(message.Holder)); } catch (Exception ex) { throw new PayloadSerializationException(message.OriginatorKey, ex); } }
/// <summary> /// This method extracts the binary blob from the message and deserializes and returns the object. /// </summary> /// <param name="srz">The serialization container.</param> /// <param name="message">The service message.</param> /// <returns>Returns the object deserialized from the binary blob.</returns> public static object PayloadDeserialize(this IPayloadSerializationContainer srz, ServiceMessage message) { try { if (message.Holder?.Blob == null) { return(null); } return(srz.PayloadDeserialize(message.Holder)); } catch (Exception ex) { throw new PayloadDeserializationException(message.OriginatorKey, ex); } }
/// <summary> /// This method tries to extract an entity from the message if present. /// </summary> /// <typeparam name="P">The payload message type.</typeparam> /// <param name="srz">The serialization container.</param> /// <param name="message">The service message.</param> /// <param name="entity">The deserialized entity</param> /// <returns>Returns true if the message is present.</returns> public static bool PayloadTryDeserialize <P>(this IPayloadSerializationContainer srz, ServiceMessage message, out P entity) { entity = default(P); if (message?.Holder == null) { return(false); } entity = srz.PayloadDeserialize <P>(message); return(true); }
public ChannelNotFoundException(string channelName, ServiceMessage message) { }
/// <summary> /// This method clones a message and then changes its destination information to match the parameters passed. /// </summary> /// <param name="message">The original message.</param> /// <param name="channelId">The delivery channelId</param> /// <param name="messageType">The message channelId</param> /// <param name="actionType">The message action channelId</param> /// <param name="priority">This is the optional priority. If this is set to a value it will replace the original priority.</param> /// <returns>The cloned message with the alternative destination information.</returns> public static ServiceMessage Forward(this ServiceMessage message, string channelId, string messageType, string actionType, int?priority = null) { return(message.Clone().SetDestination(channelId, messageType, actionType, priority)); }
/// <summary> /// This method gets the response destination as a ServiceMessageHeader object. /// </summary> /// <param name="message">The service message.</param> /// <returns>The header.</returns> public static ServiceMessageHeader ResponseGet(this ServiceMessage message) { return(new ServiceMessageHeader(message.ResponseChannelId, message.ResponseMessageType, message.ResponseActionType)); }
public static TransmissionPayload Create() { var message = new ServiceMessage(); return(new TransmissionPayload(message)); }
/// <summary> /// This extracts a service message request in to a single key request. /// </summary> /// <param name="message">The service message.</param> /// <returns>Returns the key.</returns> public static string ToKey(ServiceMessage message) { return(ToKey(message.ChannelId, message.MessageType, message.ActionType)); }
public ChannelTypeNotSupportedException(string channelType, ServiceMessage message = null) { }
public ChannelNotEnabledException(string channelType, ServiceMessage message) { }
/// <summary> /// This method serializes a Service Message using a JSON serializer. /// </summary> /// <param name="message">The message to clone.</param> /// <returns>A byte array of the original message.</returns> public static byte[] PayloadJsonSerialize(this ServiceMessage message) { //First clone the service message. return(sSerializer.Serialize(message)); }
/// <summary> /// This method gets the destination as a ServiceMessageHeader object. /// </summary> /// <param name="message">The service message.</param> /// <returns>The header.</returns> public static ServiceMessageHeader DestinationGet(this ServiceMessage message) { return(new ServiceMessageHeader(message.ChannelId, message.MessageType, message.ActionType)); }
/// <summary> /// This method unpacks the azure service bus message in to a generic ServiceMessage object /// which can be processed by the service.. /// /// </summary> /// <param name="bMessage">The Azure BrokeredMessage to convert.</param> /// <returns>Returns a generic ServiceMessage class for processing.</returns> public static ServiceMessage Unpack(BrokeredMessage bMessage) { var sMessage = new ServiceMessage(); if (bMessage.Properties.ContainsKey("SecuritySignature")) { sMessage.SecuritySignature = bMessage.Properties["SecuritySignature"] as string; } sMessage.EnqueuedTimeUTC = bMessage.EnqueuedTimeUtc; sMessage.OriginatorKey = bMessage.Properties["OriginatorKey"] as string; sMessage.OriginatorServiceId = bMessage.Properties["OriginatorServiceId"] as string; sMessage.OriginatorUTC = (DateTime)bMessage.Properties["OriginatorUTC"]; sMessage.ResponseChannelId = bMessage.Properties["ResponseChannelId"] as string; if (bMessage.Properties.ContainsKey("ResponseMessageType")) { sMessage.ResponseMessageType = bMessage.Properties["ResponseMessageType"] as string; } if (bMessage.Properties.ContainsKey("ResponseActionType")) { sMessage.ResponseActionType = bMessage.Properties["ResponseActionType"] as string; } if (bMessage.Properties.ContainsKey("ResponseChannelPriority")) { string value = bMessage.Properties["ResponseChannelPriority"] as string; int responsePriority; if (string.IsNullOrEmpty(value) || !int.TryParse(value, out responsePriority)) { responsePriority = 0; } sMessage.ResponseChannelPriority = responsePriority; } sMessage.ChannelId = bMessage.Properties["ChannelId"] as string; sMessage.MessageType = bMessage.Properties["MessageType"] as string; sMessage.ActionType = bMessage.Properties["ActionType"] as string; sMessage.IsNoop = bMessage.Properties["IsNoop"] as string == "1"; sMessage.IsReplay = bMessage.Properties["IsReplay"] as string == "1"; if (bMessage.Properties.ContainsKey("ProcessCorrelationKey")) { sMessage.ProcessCorrelationKey = bMessage.Properties["ProcessCorrelationKey"] as string; } sMessage.CorrelationKey = bMessage.Properties["CorrelationKey"] as string; sMessage.CorrelationServiceId = bMessage.Properties["CorrelationServiceId"] as string; DateTime serviceUTC; if (bMessage.Properties.ContainsKey("CorrelationUTC") && DateTime.TryParse(bMessage.Properties["CorrelationUTC"] as string, out serviceUTC)) { sMessage.CorrelationUTC = serviceUTC; } sMessage.DispatcherTransitCount = (int)bMessage.Properties["DispatcherTransitCount"]; sMessage.Status = bMessage.Properties["Status"] as string; sMessage.StatusDescription = bMessage.Properties["StatusDescription"] as string; sMessage.Blob = bMessage.GetBody <byte[]>(); sMessage.FabricDeliveryCount = bMessage.DeliveryCount; return(sMessage); }
/// <summary> /// This method clones a message and then changes its destination information to match the contract. /// </summary> /// <typeparam name="C">The contract type.</typeparam> /// <param name="message">The message to forward.</param> /// <param name="priority">This is the optional priority. If this is set to a value it will replace the original priority.</param> /// <returns>The cloned message with the alternative destination information.</returns> public static ServiceMessage Forward <C>(this ServiceMessage message, int?priority = null) where C : IMessageContract { return(message.Clone().SetDestination <C>(priority)); }
/// <summary> /// This static method creates a new TransmissionPayload object with an empty ServiceMessage. /// </summary> /// <returns>Returns the payload.</returns> public static TransmissionPayload Create(bool traceEnabled = false) { var message = new ServiceMessage(); return(new TransmissionPayload(message, traceEnabled: traceEnabled)); }
/// <summary> /// This extension method sets the message status. /// </summary> /// <param name="message">The message.</param> /// <param name="status">The status string.</param> /// <param name="statusDescription">The status description.</param> public static void StatusSet(this ServiceMessage message, string status, string statusDescription) { message.Status = status; message.StatusDescription = statusDescription; }
/// <summary> /// This method tries to extract an entity from the message if present. /// </summary> /// <param name="srz">The serialization container.</param> /// <param name="message">The service message.</param> /// <param name="entity">The deserialized entity</param> /// <returns>Returns true if the message is present.</returns> public static bool PayloadTryDeserialize(this IPayloadSerializationContainer srz, ServiceMessage message, out object entity) { entity = null; if (message?.Blob == null) { return(false); } entity = srz.PayloadDeserialize(message); return(true); }