Ejemplo n.º 1
0
        public virtual Message ToMsmqMessage(IMessage message)
        {
            Message      msmqMessage = new Message();
            PrimitiveMap metaData    = new PrimitiveMap();

            ConvertMessageBodyToMSMQ(message, msmqMessage);

            if (message.NMSTimeToLive != TimeSpan.Zero)
            {
                msmqMessage.TimeToBeReceived = message.NMSTimeToLive;
            }

            if (message.NMSCorrelationID != null)
            {
                metaData.SetString("NMSCorrelationID", message.NMSCorrelationID);
            }

            msmqMessage.Recoverable   = (message.NMSDeliveryMode == MsgDeliveryMode.Persistent);
            msmqMessage.Priority      = ToMessagePriority(message.NMSPriority);
            msmqMessage.ResponseQueue = ToMsmqDestination(message.NMSReplyTo);
            if (message.NMSType != null)
            {
                msmqMessage.Label = message.NMSType;
            }

            // Store the NMS meta data in the extension area
            msmqMessage.Extension = metaData.Marshal();
            return(msmqMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the specified NMS message to an equivalent MSMQ message.
        /// </summary>
        /// <param name="message">NMS message to be converted.</param>
        /// <result>Converted MSMQ message.</result>
        public virtual Message ToMsmqMessage(IMessage message)
        {
            Message      msmqMessage  = new Message();
            PrimitiveMap propertyData = new PrimitiveMap();

            ConvertMessageBodyToMSMQ(message, msmqMessage);

            if (message.NMSTimeToLive != TimeSpan.Zero)
            {
                msmqMessage.TimeToBeReceived = message.NMSTimeToLive;
            }

            if (message.NMSCorrelationID != null)
            {
                propertyData.SetString("NMSCorrelationID", message.NMSCorrelationID);
            }

            msmqMessage.Recoverable   = (message.NMSDeliveryMode == MsgDeliveryMode.Persistent);
            msmqMessage.Priority      = ToMsmqMessagePriority(message.NMSPriority);
            msmqMessage.ResponseQueue = ToMsmqDestination(message.NMSReplyTo);
            if (message.NMSType != null)
            {
                if (SetLabelAsNMSType)
                {
                    propertyData.SetString("NMSType", message.NMSType);
                }
                else
                {
                    msmqMessage.Label = message.NMSType;
                }
            }

            // Populate property data
            foreach (object keyObject in message.Properties.Keys)
            {
                string key = (keyObject as string);
                object val = message.Properties[key];
                if (!SetLabelAsNMSType && string.Compare(key, "Label", true) == 0 && val != null)
                {
                    msmqMessage.Label = val.ToString();
                }
                else
                {
                    propertyData[key] = val;
                }
            }

            // Store the NMS property data in the extension area
            msmqMessage.Extension = propertyData.Marshal();
            return(msmqMessage);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts an NMS message body to the equivalent MSMQ message body.
 /// </summary>
 /// <param name="message">Source NMS message.</param>
 /// <param name="answer">Target MSMQ message.</param>
 protected virtual void ConvertMessageBodyToMSMQ(IMessage message, Message answer)
 {
     if (message is TextMessage)
     {
         TextMessage textMessage = message as TextMessage;
         byte[]      buf         = Encoding.UTF32.GetBytes(textMessage.Text);
         answer.BodyStream.Write(buf, 0, buf.Length);
         answer.AppSpecific = (int)NMSMessageType.TextMessage;
     }
     else if (message is BytesMessage)
     {
         BytesMessage bytesMessage = message as BytesMessage;
         bytesMessage.Reset();
         answer.BodyStream.Write(bytesMessage.Content, 0, bytesMessage.Content.Length);
         answer.AppSpecific = (int)NMSMessageType.BytesMessage;
     }
     else if (message is ObjectMessage)
     {
         ObjectMessage objectMessage = message as ObjectMessage;
         answer.Body        = objectMessage.Body;
         answer.AppSpecific = (int)NMSMessageType.ObjectMessage;
     }
     else if (message is MapMessage)
     {
         MapMessage   mapMessage = message as MapMessage;
         PrimitiveMap mapBody    = mapMessage.Body as PrimitiveMap;
         byte[]       buf        = mapBody.Marshal();
         answer.BodyStream.Write(buf, 0, buf.Length);
         answer.AppSpecific = (int)NMSMessageType.MapMessage;
     }
     else if (message is StreamMessage)
     {
         StreamMessage streamMessage = message as StreamMessage;
         answer.AppSpecific = (int)NMSMessageType.StreamMessage;
         // TODO: Implement
     }
     else if (message is BaseMessage)
     {
         answer.AppSpecific = (int)NMSMessageType.BaseMessage;
     }
     else
     {
         throw new Exception("unhandled message type");
     }
 }