消息队列写入内容后,读出来的自动包裹了<string>标签,自定义格式化器解决该issue

/// <summary>
    /// 该格式化器使输入即输出
    /// </summary>
    public class StringFormatter : IMessageFormatter
    {
       
        public bool CanRead(Message message)
        {
            return false;
        }

        public object Read(Message message)
        {
            return null;
        }

        public void Write(Message message, object obj)
        {
            var b = Encoding.UTF8.GetBytes(obj + "");
            var m = new MemoryStream(b);
            message.BodyStream = m;
        }

        public object Clone()
        {
            return null;
        }
    }




//......
 MessageQueue.Formatter = new StringFormatter();
//......

 

posted @ 2015-03-23 15:30  二师弟tl  阅读(242)  评论(0编辑  收藏  举报