msmq multiple message types in a single queue

亡梦爱人 提交于 2019-12-12 02:18:45

问题


I'm planning on having a single queue receive ~100 different message types.

If I had only had 2 different types I'd do something like this

MessageQueue queue = new MessageQueue(_queue); queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(CreateReportComand), typeof(CreateReportComand2)});

Is it craziness to pass XmlMessageFormatter an array of ~100 Types. And if not what is the best way to examine the received message to decide how to handle it?


回答1:


You can use the WCF MsmqIntegrationBinding and handle messages of type MsmqMessage<string>. Then your handler method will receive the serialized message as a string and can do what you want with it after that.




回答2:


I preffer not to use Message.Formatter and Message.Body. Instead I use Message.BodyStream manualy serializing/deserializing my messages. Type of the message can be embeded in serialized data (that is what I do) or you can put it on message header or on label.



来源:https://stackoverflow.com/questions/8166924/msmq-multiple-message-types-in-a-single-queue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!