问题
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