1. Problem
You have a scenario where you
want to subscribe to a message differently based on the contents or
context of the message, and you need to understand how BizTalk Server
exposes this metadata.
2. Solution
In order to promote
instance-specific data fields (data that resides in the actual message
instances, such as a customer name or the ID of an order), you must
create a property schema. You then promote the specific schema elements,
attributes, or records you need to subscribe to into the property
schema. This task is accomplished in Visual Studio, and can be done in
one of two ways: quick promotion and regular promotion.
In addition to
instance-specific data fields, a number of system- or exchange-specific
properties are automatically promoted by BizTalk Server. A description
of these exchange-specific properties, and the fundamental difference
between them and instance-specific properties.
All properties that have
been promoted, regardless of whether they are associated with a specific
instance or the message exchange in general, are available for
subscription by other BizTalk Server objects, including send ports, send
port groups, and orchestrations. Promoted properties are also available
for tracking purposes, which allow them to be used in troubleshooting
and reporting.
3. How It Works
The importance of promoted
properties in BizTalk Server's publish/subscribe architecture cannot be
overstated. Understanding how they work is absolutely critical when
designing and building an integration solution.
From a simplistic
perspective, a publish/subscribe integration architecture involves
source systems publishing or outputting messages to a centralized hub.
After the hub receives these messages, it delivers them to the
destination, or subscribing, systems. Within BizTalk Server, promoted
properties are the key data that determine which messages are delivered
to subscribing systems or processes. Without promoted properties,
messages would be received by BizTalk Server, but they would not be sent
out, resulting in a sort of black hole of messages. This would
obviously not be a good situation, and BizTalk Server will actually
throw an error if a message is received without having a system or
process that subscribes to it. This keeps with the theory that it is not
a good idea for a publish/subscribe integration hub to accept messages
for which it does not have a subscriber.
A term that is commonly
used to describe a message's promoted properties is message context. The
message context includes all the instance-specific and exchange-specific
data fields and essentially is the metadata that the messaging engine
of BizTalk Server uses to process messages. As previously noted,
instance-specific properties are those that pertain to a specific
message instance, and they must be promoted explicitly during
development. A common example of this type of property is an XML element
containing a unique ID, which may capture an important data field such
as an order number. From a message schema, XML elements, attributes, and
records may be promoted.
NOTE
In order for an XML
record to be promoted, its ContentType
property must be set to SimpleContent.
All promoted properties, regardless of whether they are populated by
XML elements, attributes, or records, have a maximum length of 255
characters.
Along with being the key data
elements allowing message subscription, promoted properties are also
commonly used in orchestrations to determine business process.
Orchestrations can handle messages dynamically by interrogating promoted
properties that hold key metadata elements of a message. For example,
sales orders being delivered domestically may need to be handled
differently than those being sent overseas. By capturing the destination
country of an order in the document schema and flagging the element as a
promoted property, this data element can easily be used as a decision
point in the orchestration. Domestic orders could be handled on one
branch of decision logic, and international orders handled on another.
It is important to note here that as an alternative to using promoted
properties, the actual XML message could be interrogated within the
orchestration to determine the destination of a sales order. While this
method could be used, leveraging promoted properties simplifies
programming and has performance benefits, as promoted properties can be
accessed directly without incurring the cost of opening the entire XML
message.
For additional performance gains, distinguished fields
can be used as opposed to promoted properties within orchestrations.
Distinguished fields provide functionality similar to promoted
properties (allowing access to instance- or exchange-specific metadata
items on a message), with a few key differences:
Distinguished
fields are available only within a single orchestration instance, and
they are not available to other BizTalk Server objects, such as receive
locations, send ports, send port groups, and tracking utilities.
Distinguished fields can be of any
length; promoted properties have a maximum length of 255 characters.
Distinguished fields
have less of a performance impact than promoted properties, as they are
not persisted to the MessageBox database. Instead, they are essentially
XPath aliases, which simply point to the appropriate XML data field.
Additionally, adding the DistinguishedField
attribute to a field on a .NET class allows it to be exposed as a
distinguished field.
Distinguished
fields are accessed through a reference to the name of the message, the
name of the record structure containing the distinguished field (which
could include multiple levels of child records), and the name of the
distinguished field, with each named item separated by periods: MessageName.RecordName.ChildRecordName.DistinguishedFieldName. Promoted properties, on the other hand, are
accessed through a reference to the name of the message, the name of the
property schema, and a name of the promoted property, via the following
format:
MessageName(PropertySchemaName.PromotedPropertyName).
Certain scenarios
will call for sensitive information, such as a bank account number, to
be used as a promoted property. To allow for enhanced troubleshooting
and detailed reporting, promoted properties can be viewed in tools such
as the Group Hub reports in the BizTalk Admin Console and Business
Activity Monitor (BAM). Based on privacy regulations, these data fields
may need to be hidden from these tools, which can be accomplished by
setting the promoted property's Sensitive Information property
to True (this configuration is applied on
the property schema).
System- or exchange-specific
properties are those that are automatically promoted by BizTalk Server
and allow the successful processing of those documents by the messaging
engine. The fundamental difference between the two types of properties
is that exchange-specific properties can all be determined without
looking into the actual contents, or payload, of the message.
Instance-specific properties, on the other hand, are all populated with
actual values within a message instance.
Exchange-specific properties come in various types. Table 1 lists the default exchange-specific
property types that come with a complete installation of BizTalk Server.
Additional properties may be added as other BizTalk related items are
installed, such as the MQ Series adapter.
Table 1. Default Exchange-Specific Property
Types
Type | Description |
---|
BizTalk Framework (BTF2) | Properties that support the
BizTalk Framework. These are very rarely used in the routing of
documents. |
BizTalk Server (BTS) | Properties that support core BizTalk Server messaging. These
are extremely common in routing and include things like ReceivePortName and other standard properties that are useful to
route on. |
EDI (EDI) | These are the base EDI properties
are available when the BizTalk EDI components have been installed. They
include envelope information, party information, and other data related
to EDI message processing. |
AS2 (EdiIntAS) | These properties are
related to AS2 (also known as EDI over the Internet) messages and are
available on messages processed using the AS2 protocol. |
EDI Override
(EDIOverride) | These properties are used primarily to override
the values of EDI messages at runtime. They include envelope segments
and several other related properties. |
Error
Reporting (ErrorReport) | Properties that support error
reporting and handling. These are used when subscribing to documents
that have failed on ports that have been enabled for routing of failed
documents. |
Legacy (LEGACY) | Properties that support
BizTalk Server 2002 properties. |
Message Tracking (MessageTracking) | Properties that support
message tracking. |
Orchestration (Microsoft.BizTalk.XLANGs.BTXEngine) | Properties
that support the BizTalk Server orchestration engine. |
MIME (MIME) | Properties
that support the processing of MIME-encoded messages. |
Various BizTalk Adapters
(FILE, FTP, HTTP, MQSeries, MSMQ, MSMQT, POP3, SMTP, SOAP, SQL, WCF,
WSS, etc.) | Properties that support the different adapters, both
standard (such as File and FTP) and third-party adapters. These
properties are available for documents that have been processed using
the specific adapter (for example, if a message was received on a File
adapter, the file promoted properties will be populated). |
XML Document (XMLNorm) | Properties
that support the processing of XML documents. |
BizTalk Server
processes promoted properties as messages are received into or sent out
of the MessageBox. Specifically, pipelines handle this task. System- or
exchange-specific properties are promoted by default, through pipelines
such as XML or PassThru (both the receive and send variety). For
instance-specific properties to be promoted, a pipeline other than the
PassThru must be used, as this pipeline does not attempt to match
messages to their associated schemas (and therefore property schemas).
As properties are promoted,
their XSD data types are converted to Common Language Runtime (CLR) data
types. Table 2 shows XSD data types and their
associated CLR data types.
Table 2. XSD Data Types and
Associated CLR Data Types
XSD | CLR | XSD | CLR |
---|
anyURI | String | Name | String |
Boolean | Boolean | NCName | String |
byte | sbyte | negativeInteger | Decimal |
date | DateTime | NMTOKEN | String |
dateTime | DateTime | nonNegativeInteger | Decimal |
decimal | Decimal | nonPositiveInteger | Decimal |
double | Double | normalizedString | String |
ENTITY | String | NOTATION | String |
float | Single | positiveInteger | Decimal |
gDay | DateTime | QName | String |
gMonth | DateTime | short | Int16 |
gMonthDay | DateTime | string | String |
ID | String | time | DateTime |
IDREF | String | token | String |
int | Int32 | unsignedByte | Byte |
integer | Decimal | unsignedInt | Uint32 |
language | String | unsignedShort | Uint16 |
In addition to
pipelines, orchestrations may also be used to explicitly set promoted
properties. This is important if your business process requires the
copying or creation of messages. Since messages are immutable (meaning
once a message has been created, it cannot be modified) in BizTalk
Server, a new message must be created prior to any of its promoted
properties being set. When a message is constructed in an orchestration
as a copy of another message, the message context (its promoted
properties), by default, are all copied to the new message. Once this
new message is created, its properties may be explicitly set to
something different than in the original message. This must be done in
the same Message Assignment shape in the orchestration as the duplicate
message.
NOTE
When a copy of a message is
created in an orchestration, it is important to consider how the
properties on the original message are configured. If any of its
properties are configured to use MessageContextPropertyBase for
the Property Schema Base (a property
of the promoted field found in the property schema), they will not be
copied to the new message in the orchestration. By contrast, all those
properties that are configured to use the MessageDataPropertyBase
(the default value) for the Property Schema Base will be copied to the new message.