protected virtual BaseMessage CreateNmsMessage(Message message)
        {
            BaseMessage result = null;

            if ("amqp/map" == message.ContentType)
            {
                Dictionary <string, object> dict = new Dictionary <string, object>();
                message.GetContent(dict);
                PrimitiveMap bodyMap = new PrimitiveMap();
                SetNmsPrimitiveMap(bodyMap, dict);
                MapMessage mapMessage = new MapMessage();
                mapMessage.Body = bodyMap;
                result          = mapMessage;
            }
            else if ("amqp/list" == message.ContentType)
            {
                Collection <object> coll = new Collection <object>();
                message.GetContent(coll);
                ObjectMessage objMessage = new ObjectMessage();
                objMessage.Body = ConvertAmqpListToObject(coll);
                result          = objMessage;
            }
            else
            {
                TextMessage textMessage = new TextMessage();
                textMessage.Text = message.GetContent();
                result           = textMessage;
            }

            return(result);
        }
Пример #2
0
        public override object Clone()
        {
            MapMessage mm = (MapMessage)base.Clone();
            DefaultMessageConverter     msgConverter = new DefaultMessageConverter();
            Dictionary <string, object> properties   = new Dictionary <string, object>();

            properties = msgConverter.FromNmsPrimitiveMap((PrimitiveMap)body);
            msgConverter.SetNmsPrimitiveMap(mm.body, properties);
            return((MapMessage)mm);
        }
        protected virtual Message CreateAmqpMessage(IMessage message)
        {
            if (message is TextMessage)
            {
                TextMessage textMessage = message as TextMessage;
                Message     result      = new Message(textMessage.Text);
                return(result);
            }
            else if (message is BytesMessage)
            {
                BytesMessage bytesMessage = message as BytesMessage;
                Message      result       = new Message(bytesMessage.Content, 0, bytesMessage.Content.Length);
                return(result);
            }
            else if (message is ObjectMessage)
            {
                ObjectMessage       objectMessage = message as ObjectMessage;
                Collection <object> objs          = new Collection <object>();
                objs = ConvertObjectToAmqpList(objectMessage.Body);

                Message result = new Message(objs);
                return(result);
            }
            else if (message is MapMessage)
            {
                MapMessage   mapMessage          = message as MapMessage;
                PrimitiveMap mapBody             = mapMessage.Body as PrimitiveMap;
                Dictionary <string, object> dict = FromNmsPrimitiveMap(mapBody);

                Message result = new Message(dict);
                return(result);
            }
            else if (message is StreamMessage)
            {
                StreamMessage streamMessage = message as StreamMessage;
                Message       result        = new Message(streamMessage.Content, 0, streamMessage.Content.Length);
                return(result);
            }
            else if (message is BaseMessage)
            {
                Message result = new Message();
                return(result);
            }
            else
            {
                throw new Exception("unhandled message type");
            }
        }
        protected virtual BaseMessage CreateNmsMessage(Message message)
        {
            BaseMessage result = null;

            if ("amqp/map" == message.ContentType)
            {
                Dictionary<string, object> dict = new Dictionary<string,object>();
                message.GetContent(dict);
                PrimitiveMap bodyMap = new PrimitiveMap();
                SetNmsPrimitiveMap(bodyMap, dict);
                MapMessage mapMessage = new MapMessage();
                mapMessage.Body = bodyMap;
                result = mapMessage;
            }
            else if ("amqp/list" == message.ContentType)
            {
                Collection<object> coll = new Collection<object>();
                message.GetContent(coll);
                ObjectMessage objMessage = new ObjectMessage();
                objMessage.Body = ConvertAmqpListToObject(coll);
                result = objMessage;
            }
            else
            {
                TextMessage textMessage = new TextMessage();
                textMessage.Text = message.GetContent();
                result = textMessage;
            }

            return result;
        }