BRE Rules Evaluation in ESB Toolkit: Document Types Are Different than Expected
One thing that is incredibly useful about the use of an ESB Toolkit Itinerary is that decisions can be made at runtime regarding the routing of messages or selection of transformations to execute against messages. For my projects, the most useful tool to facilitate this resolution has been the Business Rules Engine that comes with BizTalk.
When you use a BRE resolver, you have the option to select whether the Rules Engine will use only the context of the message you pass into the engine (the default setting) or you can have the Rules Engine use the content of the message as well by setting the useMsg attribute to true.
I have not experienced any problems when using message context as evaluation criteria in my rules but until recently I have been unsuccessful in using the message content as part of the evaluation criteria. The trouble I had was that regardless of how I arranged the Facts in the Business Rule Composer, the evaluation always returned false and the rule never fired while processing the message.
This is truly a frustrating scenario. Here is the error message you will most often see (or something similar):
Fortunately I found this interesting tidbit: the Document Type that the Itinerary components send into the BRE is not what you expect. Instead of the Document Type that shows up in the Rules Composer when you select your fact from an XML schema (like the schema name, for example), it sends in Microsoft.Practices.ESB.ResolveProviderMessage instead.
So what do you do?
One work-around is to replace the Document Type attribute in the BRE Rule Composer from its default to Microsoft.Practices.ESB.ResolveProviderMessage. This will allow the rules engine to recognize the document type and fire rules correctly as it processes the message .
- Open the Business Rule Composer
- In the Facts explorer, select “XML Schema” and load whichever schemas you will need to work with.
- Select the schema name. Note the Document Type property in the Properties Window. It will be the same name as your schema.
- Change the Document Type property’s value to Microsoft.Practices.ESB.ResolveProviderMessage for each schema.
- Drag-and-Drop nodes from the schema into the Conditions section as you normally do. Note that the new type is represented with the XPath in your conditions.
When the rules execute, it should now be able to find the referenced nodes and evaluate your rules correctly.