Biztalk messaging services, working with messages.


Introduction

This article is intended to illustrate the main concepts of messaging and the realization in Biztalk Server 2006 as a Message-Oriented Middleware (MOM) platform. Biztalk messaging service is the core major component within the platform because it allows the communication between internal components of Biztalk Server as well as with external systems.

The most important business entity in Biztalk Server is the Message.  Biztalk messaging services follow the exchange design pattern
"pub/sub". That is, every message which is going into the Message box, which is the core of the messaging subsystem and has the responsibility of storing all the message instances, is published so that endpoints (orchestrations and send ports) matching with message subscriptions can consume it. Messages are immutable, that is one message that is created cannot be changed, and in order to make a change, a new message must be created. One interesting aspect of messages, is that they are not really a single entity; instead, each one is composed of one or more message parts which in turn have their own payload.

Each message has an underlying schema which defines its structure. This schema in Biztalk Server is specified using XML schemas (XSD files). As well each message has a metadata associated with it called the message context and each individual item is stored in key/value format called the context properties. These message context properties are defined using property schema. This property schema is associated to the schema of the message. Context properties define the subscriptions and are the main mechanism used to evaluate which endpoint (orchestration or send port) has an associated valid subscription.

Although messages are represented as XML documents internally, there are mainly two formats of messages that can be sources of information: XML files and flat files.

Creating a XML Schema file

The steps to create a schema for a message are:

1.      Start Visual Studio 2005.

2.      Create a Biztalk Project by clicking on File|New|Project.

3.     Choose to create an Empty Biztalk Server Project, and enter a name and a location for the solution as shown in Figure 1.



Figure 1

4.     Create a schema by clicking on Project|Add New Item as shown in Figure2.



Figure 2

5.      Right-click the Root node and select rename and enter Purchase Order.

6.      Right-click the Purchase Order node and select Insert Schema Node. You can see that you have several options. Select Child Record option and enter Customer as the name.

7.      Right-click the Customer node, and select Insert Schema Node|Child Field Element and enter Name as name.

8.      Repeat step 7 and add the following fields: Name, Address, City, State, Zip and Phone.

9.      Right-click the Purchase Order node and select Insert Schema Node. You can see that you have several options. Select Child Record option and enter Item as the name.

10.  In the Properties window, set Max Occurs property to * (unbounded) symbol.

11.  Right-click the Item node, and select Insert Schema Node|Child Field Element and enter Id as name.

12.  In the Properties window, set Data Type property to xs:int.

13.  Repeat step 11 and 12 and add the following field: Amount.

The final schema is shown in Figure 3.



Figure 3

Once you create the XML Schema, you can test it by creating a sample XML file.

Right-click the PurchaseOrder.xsd file inside the Solution Explorer window, and select Generate Instance. A link to the output file is shown the Output window.

Message Context Properties

Promoted properties allow the Messaging Engine to route messages. This approach is called content-based routing. You need to create a custom property schema to define these context properties. In order to promote a property within Biztalk Server, you have two options: quick and manual promotion.

Let's suppose, we want to route and process the Purchase Order documents by state, so we decided to promote the State attribute of Purchase Order schema.

Following the quick promotion approach, right-click the State node inside the Purchase Order schema and choose Promote|Quick Promotion. Then, Biztalk schema editor will create a new property schema file and add an XML reference to the new property schema as shown in Figure 4.



Figure 4

In order to promote a property manually, you need to create a property schema file, and create elements that hold the promoted values. Finally, this property schema is associated to the main content schema using the Show Promotions function of the schema editor.

These properties can be accessed from orchestration, routing, adapters and pipelines.

There is another type of promoted properties called distinguished fields that cannot be used for routing and are only used by the orchestration engine to move required elements into the context and only read the context property without having to load the entire document into memory. They offer Intelligence capabilities within orchestration expression editor.

Let's define a distinguished field. Let's suppose we want to make decision inside
orchestrations by the Zip values. So, right-click the Zip node inside the Purchase Order schema and choose Promote|Show Promotions. Then click on the Distinguished Fields tab, and click on the Add button as shown in Figure 5.



Figure 5

Conclusion

In this article, I covered some of the principles of Messaging Service on Biztalk Server specifically about messages, message schema, message context and property schema using some practical examples.