SQL Server with Mr. Denny

May 15 2008   11:00AM GMT

Back To Basics: Service Broker Message Types



Posted by: mrdenny
SQL, Service Broker, Back To Basics, Message Type

The message type is the first of the service broker specific objects.  The message type defines the name of the message, and performs any validation that the service broker needs to do on the contents of the message prior to sending the message.  If the message is being sent to another database (on the same server or a different server) then the message type must exist on both databases.

Validation can be one of four options.

  1. None (My personal favorate especially for sample code)
  2. Empty
  3. Well_Formed_XML
  4. Valid_XML With Schema Collection

1 and 2 are pretty straight forward.  None = No validation is done.  Empty = The message must be empty.  Well_Formed_XML requires that the XML be a valid XML document.  The fourth option requires that not only the XML be valid, but that it fits within a pre-existing XML schema collection (an XSD which has been loaded into the SQL Server).

The syntax to create a Message Type is pretty basic.

CREATE MESSAGE TYPE [MessageTypeName]
VALIDATION = NONE

That’s it.  If you need to change the schema use the AUTHORIZATION clause to set the owner of the object.

When using the validation of NONE it is up to the receiving code or application to verify that the data within the message exists and is valid.

Denny

Comment on this Post


You must be logged-in to post a comment. Log-in/Register

Improving SQL Service Broker Performance - SQL Server with Mr. Denny  |   Nov 3 2008   11:02AM GMT

[...] Message Type is called MT_ObjectDelete My Contract is called CT_ObjectDelete My Queues are called [...]


 

SQL Server – Service Broker – Message Types across Databases « Justin’s Blog  |   Jun 2 2009   11:57PM GMT

[...] Back To Basics: Service Broker Message Types Tags: Service Broker, SQL [...]