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

时间:2024-05-30 12:37:20
/// <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();
//......