A Quick Look at Business Rules in BizTalk Server 2006 by Lakshmi Murthy
After release of BizTalk Server 2006 in March this year, there has been loads of information on this version of BizTalk Server, owing to great efforts by fellow Biztalk developers & bloggers and also with good initiatives from Microsoft. To add more to this collection of information, this article attempts throws some light on the changes and enhancements available in Business Rules Engine (BRE) in BizTalk Server 2006.
Some of these new features and enhancements in BTS 2006 are listed here:
1. Static methods can be invoked in Rules
Now using BTS 2006, we can invoke a static method inside a policy. There is a misconception regarding BRE that it can understand only values passed as Facts. To certain extent, this has been true with BTS 2004, but with BTS 2006, you need not pass static methods as facts to rule engine. This means that in BTS 2006, you can invoke static functions and directly call them in the rules. For example, we can directly call DateTime.Now function or other similar standard functions inside rules without passing them as fact objects.
To add the StaticSupport registry key
- Click Start; click Run, type RegEdit, and then click OK.
- Expand HKEY_LOCAL_MACHINE, expand Software, expand Microsoft, expand BusinessRules, and then select 3.0.
- In the right pane, right-click, point to New, and then click DWORD value.
- For Name, type StaticSupport.
If the StaticSupport registry key already exists, and you need to change its value, perform the following steps.
To change the value of the StaticSupport registry key
- Click Start, click Run, type RegEdit, and then click OK.
- Expand HKEY_LOCAL_MACHINE, expand Software, expand Microsoft, expand BusinessRules, and then expand 3.0.
- Double-click the StaticSupport registry key, or right-click it and then click Modify.
The above key contains 3 valid values as shown below:
0 - This is the default value of the key and this value mimics the behavior of BizTalk Server 2004 where an instance of an object is always required as an input fact, and the method is only called when the rule is evaluated or executed.
1 - An instance of the object is NOT required, and the static method is called whenever the rule is evaluated or executed
2 - An instance of the object is NOT required, but the static method will be called at rule translation time (only if the parameters are constants). This value is primarily meant as a performance optimization. However, note that static members used as actions will NOT be executed at translation time, but static methods used as parameters may be executed.
So, obviously we need to either use 1 or 2 to enable Static support and invoke static methods directly.
2. Overriding registry key with application configuration file
The registry entries described in the topic “Rule Engine Configuration and Tuning Parameters” on MSDN can be overridden by using an application configuration file.
The registry settings are global for all applications that host a rule engine instance. You can override these registry settings at an application level by using the application configuration file. For BizTalk Server applications, the host application is the BTSNTSvc.exe and the configuration file is the BTSNTSvc.exe.config, which you can find in the BizTalk Server installation directory. You need to specify the values for the configuration parameters that you want to override in the application configuration file as show below:
<configuration>
<configSections>
<section name="Microsoft.RuleEngine"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<Microsoft.RuleEngine
UpdateServiceHost="localhost"
UpdateServicePort="3132"
UpdateServiceName="RemoteUpdateService"
CacheEntries="32"
CacheTimeout="3600"
PollingInterval="60"
TranslationTimeout="3600"
CachePruneInterval="60"
DatabaseServer="(localhost)"
DatabaseName="BizTalkRuleEngineDb"
SqlTimeout="-1"
StaticSupport="1" />
</configuration>
3. Programmatically Deploy Rules in BRE
I admit that this feature is available in both BTS 2004 as well as BTS 2006. However, we see more significance of this feature in the latest version of BizTalk Server. You can programmatically deploy rules using RuleSetDeploymentDriver class in the Microsoft.RuleEngine.RuleEngineExtensions namespace and invoke rules or policies inside your applications using RuleEngineComponentConfiguration class where you can specify custom fact retrievers.
The following shows sample code to deploy rules programmatically:
string policyName = “MedicalclaimsProcessing”;
int majorRev = Convert.ToInt16(args[1]);
int minorRev = Convert.ToInt16(args[2]);
RuleSetInfo rsinfo = new RuleSetInfo(policyName,majorRev,minorRev);
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd;
depdriver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
depdriver.Deploy(rsinfo);
If you are deploying policies to the database that your BizTalk Server environment is configured to use, you do not have to create the RuleSetDeploymentDriver object in the code. Instead, you can request the rule engine to create a RuleSetDeploymentDriver object for you by invoking the GetDeploymentDriver method of the Configuration class in the System.RuleEngine namespace. The following sample code demonstrates how to invoke the GetDeploymentDriver method:
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd;
dd = new Microsoft.RuleEngine.Configuration.GetDeploymentDriver();
The GetDeploymentDriver method retrieves the values of the DeploymentDriverAssembly and DeploymentDriverClass registry keys under HKEY_LOCAL_MACHINE\Software\Microsoft\BusinessRules\3.0, and creates an instance of DeploymentDriverClass.
The following are the two values for the above key:
DeploymentDriveAssembly- Microsoft.BizTalk.RuleEngineExtensions
DeploymentDriverClass-Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver
The RuleSetDeploymentDriver class implements the IRuleSetDeploymentDriver interface. You can develop your own policy deployment driver by creating a class that implements the IRuleSetDeploymentDriver interface and change the values for the registry keys described above as appropriate.
The above RuleEngineComponentConfiguration method inside RuleEngineComponentConfiguration class can be used to pass custom facts as shown in the code below:
RuleSetExecutionConfiguration rec1 = new RuleSetExecutionConfiguration();
RuleEngineComponentConfiguration recc1= new RuleEngineComponentConfiguration
("FactRetrieverForClaimsProcessing",
"Microsoft.Samples.BizTalk.MedicalPolicies.
FactRetrieverForClaimsProcessing.DbFactRetriever");
rec1.FactRetriever = recc1;
rs1.ExecutionConfiguration = rec1;
Apart from the above, a new method named Clear has been added to Policy class which resets the memory of the rule engine instance created for execution of the policy. Also support for Nullable types, generic methods and classes are other enhancements of Business Rules Engine in BizTalk Server 2006.
About Lakshmi Murthy:
Lakshmi Murthy is a BizTalk MVP and Architect for IBM India. She is the founder of BizTalk User Group-India. She has authored many white papers on different Microsoft Technologies in MSDN and other web sites. She actively contributes to BizTalkIndia.com. She blogs regularly at her blog at http://techsavygal.wordpress.com.
Pro BizTalk 2006 Book Now Available on Amazon.com
APress has related a new BizTalk 2006 book. It is now available on Amazon.com. This book is called Pro BizTalk 2006.
Book Description: Pro BizTalk 2006 is a high-end resource that is based on real feedback from BizTalk developers. Authors George Dunphy and Ahmed Metwally are well known within the BizTalk community, and here they cover topics not discussed in other books, like performance tuning, scalability, and administration. This book also features examples of specific, real-world implementations.
Amazon.com also has a combo to purchase the Pro BizTalk 2006 book along with the highly rated BizTalk 2006 Recipes book. This combo is currently priced at $70.78.
View all of Amazon.com's BizTalk 2006 Book Offerings. |
|
Call an Orchestration from Another or use Direct Binding?
This is a common scenario I see - to use the Call Orchestration Shape or use Direct Binding? See what Tomas Restrepo and I have to say on the subject in this form post.
Comments or Suggestions?
I welcome comments, questions, and suggestions. After all, this newsletter is about delivering content you want to hear about! Feel free to contact me through the forum or via e-mail.
Until next time...
Stephen W. Thomas -
BizTalkGurus.com
The Bottom Line:
In the past 5 months I have had to file 2 police reports from items being lost or stolen. Funny thing is the same of the same items were involved each time. The latest incident resulted in my Bose Headphones (and other items) walking away from the rental car counter at the airport...
|