public virtual IMessage ToNmsMessage(Message message) { BaseMessage answer = CreateNmsMessage(message); // Get the NMS meta data from the extension area PrimitiveMap metaData = PrimitiveMap.Unmarshal(message.Extension); try { answer.NMSMessageId = message.Id; answer.NMSCorrelationID = metaData.GetString("NMSCorrelationID"); answer.NMSDeliveryMode = (message.Recoverable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent); answer.NMSDestination = ToNmsDestination(message.DestinationQueue); } catch (InvalidOperationException) { } try { answer.NMSType = message.Label; answer.NMSReplyTo = ToNmsDestination(message.ResponseQueue); answer.NMSTimeToLive = message.TimeToBeReceived; } catch (InvalidOperationException) { } return(answer); }
/// <summary> /// Converts the specified MSMQ message to an equivalent NMS message. /// </summary> /// <param name="message">MSMQ message to be converted.</param> /// <param name="convertBody">true if message body should be converted.</param> /// <result>Converted NMS message.</result> public virtual IMessage ToNmsMessage(Message message, bool convertBody) { BaseMessage answer = CreateNmsMessage(message, convertBody); // Get the NMS property data from the extension area PrimitiveMap propertyData = PrimitiveMap.Unmarshal(message.Extension); try { answer.NMSMessageId = message.Id; answer.NMSCorrelationID = propertyData.GetString("NMSCorrelationID"); answer.NMSDeliveryMode = (message.Recoverable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent); answer.NMSDestination = ToNmsDestination(message.DestinationQueue); } catch (InvalidOperationException) { } try { answer.NMSReplyTo = ToNmsDestination(message.ResponseQueue); answer.NMSTimeToLive = message.TimeToBeReceived; answer.NMSPriority = ToNmsMsgPriority(message.Priority); } catch (InvalidOperationException) { } try { if (message.Label != null) { if (SetLabelAsNMSType) { answer.NMSType = message.Label; } else { answer.Properties["Label"] = message.Label; } } answer.Properties["LookupId"] = message.LookupId; } catch (InvalidOperationException) { } foreach (object keyObject in propertyData.Keys) { try { string key = (keyObject as string); if (string.Compare(key, "NMSType", true) == 0) { answer.NMSType = propertyData.GetString(key); } else if (string.Compare(key, "NMSCorrelationID", true) == 0) { answer.NMSCorrelationID = propertyData.GetString("NMSCorrelationID"); } else { answer.Properties[key] = propertyData[key]; } } catch (InvalidOperationException) { } } return(answer); }