Thursday, January 13, 2011

BizTalk Server Tutorial Part 6: Content Based Routing

Continuing the application of Part5
Create the following additional folders:
·         C:\BizTalkServerTutorial\FileDrop\SmallAmoutLoan
Charan: Our bank want to give high priority to the customer applying for loan amount more than 1000. So they want that all the loan applications below this amount should be sent to folder location ‘C:\BizTalkServerTutorial\FileDrop\SmallAmoutLoan’ so that first the application with higher loan amount can be processed from the existing folder location ‘C:\BizTalkServerTutorial\FileDrop\DestinationLocation’ if all are processed only then application from this folder location can be processed. So can BizTalk help here?
Rohit: hmmm yes of course we can do content based routing to solve the problem. Content based routing mean sending the message to destination based on the content of the message as in this case we will send message to destination based on the loan amount.
For achieving this we need to do the following steps:
First, we modify the schema ‘LoanRequest.xsd’ created in part 4 of the tutorial to promote the Amount field which would be done by creating a property schema.
Then, we need to create a send port for this new folder location and need to specify the promoted property in the filter.
Finally, we will need to modify the filter for send port ‘SP_DestinationApplication_FILE’ (created in part2 of tutorial) to route the message with amount higher than 1000 to this send port.
So open the ‘BizTalkTutorial.Part4’ solution create in part 4 of the tutorial in the Visual Studio.
Open the ‘LoanRequest.xsd schema created in Part4 of the tutorial. Right click the ‘Amount’ field and select ‘Quick Promotion’ as shown below. Click on the 'OK' button in the popup asking to add the property schema to your project.
A new property schema with name ‘PropertySchema.xsd’ will be added to the project. With two fields as shown below. Property1 filed is not required so delete this filed from the property schema. Not the target namespace of the property schema.
Rebuild the solution and deploy it again to reflect the changes in the BizTalk. Make sure your property schema has been deployed successfully to the biztalk.
Create a new send port with the following details
Name: SP_DestinationForSmallAmountLoan_FILE
Adapter Type: FILE
            Destination Folder: C:\BizTalkServerTutorial\FileDrop\SmallAmoutLoan
And specify filter as shown below:-
BTS.ReceivePortName == RP_SourceApplication  And
BizTalkTutorial.Part4.PropertySchema.Amount < 1000
See that the promoted field is coming in the dropdown for Property.
Next enlist this send port but not start it yet.

Next open the properties for send port group SendPortGroup_RoutrLoanApplications' and remove the port 'SP_DestinationApplication_FILE' from Send Port Group. 
Next change the filter of the send port ‘SP_DestinationApplication_FILE’ as shown below:-
Copy the following content into a file and paste the copy of the file in the source location (i.e. ‘C:\BizTalkServerTutorial\FileDrop\SourceLocation‘) created in part 2 of this tutorial.
BMTP2000E,Nitin,Sachdeva,1983-10-06,500
This message will not get to the destination folder because we have not started the send port.
Let us check the context of the message to see if the property gets promoted or not. Go to BizTalk Group and execute the query as shown below to see the message.
Right click the message and click on ‘Message Details’.

Check the message context to see if the Amount filed is present in the context of the message with Type = Promoted.
Now start the send port ‘SP_DestinationForSmallAmountLoan_FILE’ the message will be dropped to the required folder at destination.
Charan: So why we call it content based routing because the message get routed based on the value of property in the context of the message.
Rohit: you are right the message get routed based on the value of property promoted in the context of the message but because the value of that property is being copied from the content of the message so it is known as content based routing. In the previous case when we were routing message based on the name of the received port that is known as context based routing because the name of receive port is not get copied from the content of the message.

Charan: Another question is how this property get written to the context of the message.
Rohit: In this scenario the flat file dissembler (the flat file dissembler was used to create ReceivePipelineForLoanRequest in part 4 of this tutorial) has done this based on the information in the schema. You remember, we modified the schema 'LoanRequest.xsd' to include this information in the schema. Similarly BizTalk provide the dissembler for XML which can be used to promote properties in XML schema.
Summary
You have seen
- How to do the content based routing.   
 - How to promote properties to the context of the message by creating property schema.
- How to use property schema to route a message by setting the value of filter.
 
What has been covered till now?
I have shown you all the messaging scenarios. These are called the pure messaging scenario because no workflow (Orchestration) was needed to solve any of the problems. So you must have realized how BizTalk provide you the out of box component to solve many problems without any coding. In next few post I will explain you how orchestration get used in the BizTalk to automate some work.

4 comments:

Anonymous said...

In previous parts Send Port Group is created; After Part 6 is deployed when a file is placed at receive location (Amount < 1000), it still copies at both DestinationApplication as well as SmallLoanAmount folders. The routing works correctly only when the SendPort group is removed.

Anonymous said...

All 6 parts well explained about messaging scenarios. As you mentioned at the end of this article that Orchestration will be explained in later parts. But I didn't find any further articles related to Orchestration. Please post an article about Orchestration, this will help Biztalk beginners a lot. Keep up the good work.

Rohit C.M. Sharma said...

I have edited the post to remove send port from the send port group after this change you will see the file only in SmallLoanAmount folders when Amount < 1000.

Rohit C.M. Sharma said...

Thanks for your feedback. I will try to publish a post on orchestration.

Post a Comment