Blogging BizTalk

Lets Discuss BizTalk

Tag Archives: rules

Understanding Bussiness Rules Engine Via The Dynamic Endpoint Resolver Pattern


In this example I am going to demo how we can use Business rules engine in BizTalk to route messages dynamically.

Here is our scenario.

We receive a message having a node called PartyName.

Based on the value of PartyName the business rules policy named ‘ResolverRules’ will fetch the endpoint and adaptertype from from a SQL table named ‘RulesResolver’.This policy will be called from an orchestration which will use a dynamic send port based on the endpoint fetched by the rules.

Advantage: This will help us accomplish a decoupled messaging scenario. All we need to do is add the new PartyName and the corresponding endpoints, adapterUsed information in the SQL table and the orchestration dynamic send port will take care of the routing. Which essentially means a single send port can cater to multiple send end points.

DEMO:

STEP1: CREATING THE RULE

Create a DB and table in your SQL server. The table will have three columns for partyname adapter type and end point. Our orchestration will fetch all these information via the rules engine and assign it to the dynamic send port properties. Our table is going to look something like this.

DBTable

Open the Business Rules Composer.

Go to the facts explorer > Vocabularies tab> Select Vocabularies, right click and pick Add New Vocabularies.

Name your vocabulary as appropriate. Click on your newly created vocabulary and pick  Add new definition. We are going to define two definition one will fetch our endpoint and other will fetch the PartyName.

SetVocabulary

Once done right click on your vocabulary version and pick Publish. Without publishing the vocabulary we wont be able to use that in our rules policy. Also once the vocabulary is published it cannot be modified.If need arises we will have to publish a new version and use that instead.

VocabularyPublish

Now once vocabulary is ready we are going to create rules policy based on the DB facts and the XSD. To reference our xsd we will select the XML schemas tab and right click on schemas > Browse to our xsd file we have created in the BizTalk solution also holding our orchestration.

setxml

We are now ready to define our rules policy now. Click on policies and pick add new policy. Name it appropriately. After you are done configuring your policy the end result should look like this. The conditions we have defined has used the vocabularies we defined in the earlier step.

Please go ahead and deploy the policy.Without deploying the orchestration will not pick the rules.

policy

Now our Rules Policy is ready to be used.

STEP 2: CREATING THE ORCCHESTRATION TO CALL RULES.

Please create an orchestration looking ressembling following picture .

Orchestration

You will have to add System.data, System.transaction and Microsoft.RulesEngine reference  in the solution. Create three variable in the transaction scope of the call rule shape of the following types.

Microsoft.RuleEngine.DataConnection
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlTransaction

The expression shape in the orchestration are going to look like this.
orchexpressions

Use the call rule shape to point to our rules policy. Configure the input parameters, in this case two one message and other rules connection.

The last send port is dynamic and we will pass the port parameters in the last expression shape which in turn are derived from the message returned by rules policy. Notice the expression to assign the end point.

Now we can deploy this and our solution will be ready for testing.

Please leave me a comment if you have any questions.

Advertisements
D Goins Insperience

Technological outformation for this day and age

[INACTIVE BLOG] Connected Thoughts - Thiago Almeida

Connected systems and the occasional picture

Uri Katsir's Blog

BizTalk , BizTalk RFID and .NET

prashantbiztalkblogs

My BizTalk Experiences

BizTalk Server Tutorial

BizTalk Server Concepts and Common Errors

Extremely Talented Monkeys

A Technical Blog by Ed Jones: Azure, .NET, BizTalk, WCF, and SQL Server

On All Things Web

Discussing web development without limits

Vikas Bhardwaj's Blog

Articles about BizTalk Server and .NET C#

Cloud develop

a blog about (cloud) development... because I'm a nerd

Hooking Stuffs Together

My learning logs from day to day work experience about Integration platform using Microsoft technologies.

Connected Pawns

Mainly BizTalk & Little Chess

jhelatissimo

a blogger in the process.

MS Innovations Blog

Tips, Tricks, and Workarounds for BizTalk and other Microsoft technologies

srirambiztalks

Katradhu Kaialavu,Kalladhadhu Ulagalavu!

Vijay Microsoft Technical

BizTalk, WCF, ESB ToolKit, Windows Azure

Mind Over Messaging

Musings on BizTalk, Azure, and Enterprise Integration