One thing I use message types for is to know how I should process the message without actually having to look at the message itself. Let's say we're creating a system that will deal with conversations from disparate applications that service both the HR and Finance teams. You could argue that those belong in separate queues, but let's assume that all of those messages are going into one queue. In the procedure that I use to dequeue messages from the queue, I would have something like this (simplified):
declare @message_type_name sysname, @message_body xml);
RECEIVE TOP (1)
@message_type_name = [message_type_name],
@message_body = CAST([message_body] AS XML)
FROM [repl].[CoreQueue]
IF (@message_type_name = 'TimeOffRequest')
EXEC dbo.ProcessTimeOffRequest @message_body;
ELSE IF (@message_type_name = 'ReimbursementRequest')
EXEC dbo.ProcessReimbursementRequest @message_body;
Note I'm employing some anti-patterns here (RECEIVE
ing only one message at a time, no error handling, etc) in the interest of clarity around your actual question.
Because I know something about the content of the message based on the message type, I can quickly route the message to something that can handle it. Add to that the ability to bundle message types into contracts which can be prioritized with broker priorities and you have a fairly flexible system.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…