Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

sql server - ServiceBroker - What is sense of types of message?

Can anyone to tell me one thing ?
It is about ServiceBroker.
https://gallery.technet.microsoft.com/scriptcenter/Using-Service-Broker-for-360c961a
Following this short tutorial we can come across two thnigs:

CREATE MESSAGE TYPE [//SBM/RequestMessage] VALIDATION=WELL_FORMED_XML;  
CREATE MESSAGE TYPE [//SBM/ReplyMessage] VALIDATION=WELL_FORMED_XML;  

What is aim of this stuff ? What benefit from separating messages to two types ? And second thing: Is it possible to check if queue was disabled by poison ? I know that then queue is blocked, but I would like to be able to check it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 (RECEIVEing 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...