Wednesday 19 February 2014

Biztalk Design Patterns -- Sequential Convoy (Non-Uniform Message)

In this blog we will have look at Biztalk Pattern -- Sequential Convoy Non-Uniform.

What is Biztalk Pattern??
Biztalk Patterns are nothing but the common scenarios which we use frequently while designing the Biztalk solution.
Depending on the requirement, one has to decide which pattern to use. We can use one or more patterns in the solution.

In this blog we will understand and Implement Sequential Convoy(Non Uniform) Pattern.

What is Sequential Convoy?
Sequential Convoy is the pattern in which we group number of receive messages together in Singleton manner.


What are the scenarios where we can implement Sequential Convoy.
Case I --

Buisness Scenario -- In most cases patient also have their Mediclaim. Now we have two documents for each patient(patient info and Mediclaim).

Technical Aspects -- Patient may or may not have mediclaim. So wait for some specific time for mediclaim form if it comes then group the mediclaim and patient info and send to send folder. If Mediclaim does not come in specified time then pass on the only patient info to send folder.

Solution -- At first, We will receive patient Info form then we will wait for mediclaim form for same customer(Unique Reference ID). If if comes in specified time then club the two message for that customer and process those.

This is Non Uniform Sequential Convoy, as we grouping two different receive messages in this sequential Convoy.


Case II --

Buisness Scenario -- Suppose we are creating hospital administration system. In this case, throughout day we will keep on receiving patient Information forms. We have system which receives this form and converts that info into the other form/db.

Technical Aspects -- For every patient's form a separate Orchestration instance will get created.

Solution -- We can create bunch of Forms such as 20 forms at a time or collect all the forms after every one hour. By this way we reduce the number of Orchestration Instances.

This is Uniform Sequential Convoy, as we are using same receive message.


Enough with the theory, Lets start with the implementation of Case I with Non Uniform Sequential Convoy...

To start with, lets create three schemas:

1)schema_patient -- This will contain patient's Info



2)Schema_Medi    -- This will contain patient's mediclaim info.




3)patientForm    -- This will contain mix atrributes of PatientForm and Mediclaim Form.




4)Property111(Property Schema) -- This schema is needed for the purpose of correlation. Here we can promote the properties so that we can use them in orchestation.
In our scenario we will promote schema_patient/AdharNo, Schema_Medi/AdharNo. In the Property Schema create a new field name it as "UniqueNo".



To promote the properties go to that field -> Promote -> Show Promotion
Following window will pop up


Click on Property Fields Tab. Browse to Property file which we have created. From left panel add the field which we want to promote.

We will also create a map file which will convert schema_patient and Schema_Medi into PatientForm.It will contain following links:



Now, we are all set to design out orchestration.  Design the orchestration as below:


Explanation :
Port_1 : This is the receive port which will accept the Patient Info forms and Mediclaim Form from same location. It has two different Operations. (Operation_1) for receiving msg of type schema_patient (Operation_2) for receiving msg type Schema_Medi.
Note - Set "Ordered Delivery" property to "True". This is to specify that Msg will get delivered in sequence.

Receive_1 : This is the Starting point of Orchestration where we will receive msg of schema_patient.Set "Activate" property to "True".

Listen_1 : This Listen shape is added because we need to wait for Mediclaim for some specific time. So it will contain two branches. One branch(Receive_2) will be waiting for msg of type Schema_Medi and other(Delay_1) will wait for some time period. I have used following expression:

new System.TimeSpan(0,1,0) 
By this Listen shape will wait for 1 minute and will start the execution if other branch does not start their execution.

Correlation Set up
Create one Correlation Type with Property Field which we have set in the Property file.
Create Correlation Set based on that Correlation Type.

For Receive_1 -- Set property "Initializing Correlation Set" with name of Correlation set you created.
For Receive_2 -- Set property "Following Correlation Set" with name of Correlation set you created.

ConstructMessage1 : This construct shape contains Transform_1 shape which is having map to convert schema_patient + Schema_Medi => patientForm.

Send_2 : Send shape to send the msg of type patientForm to Send Port.

Send_1 : Send shape to send the msg of type schema_patient to Send port.

Port_2 : This is Send Port to which we will send the msgs of type patientForm.

Port_3 : This is Send Port to which we will send the msgs of type schema_patient.

With this we are done with the creation of solution, now deploy this solution.
Configure the application in Biztalk console with receive and send port configuration.
Now, lets test what we have done till now..

Generate the instance of schema_patient place it in the specified Receive folder.
My Input sample contains:
<ns0:Pat xmlns:ns0="http://Listen_Practice.schema_patient">
  <Name>FirstName</Name> 
  <LastName>LastName</LastName> 
  <Age>27</Age> 
  <ANo>1</ANo> 
  <Disease>XYZ</Disease> 
</ns0:Pat>

You wont see any output for 1 minute. This is because we have set the delay of 1 min. So Orchestration will wait for Schema_Medi msg for 1 min.

Within this 1 minute generate the instance of Schema_Medi place it in the specified Receive folder.
My Input sample contains:
<ns0:MClaim xmlns:ns0="http://Listen_Practice.Schema_Medi">
  <MNo>MNo_0</MNo> 
  <MName>MName_0</MName> 
  <AdharNo>1</AdharNo> 
</ns0:MClaim>


And when I chk the Output folder it is having following contents:
<?xml version="1.0" encoding="utf-8" ?> 
<ns0:PatientForm xmlns:ns0="http://Listen_Practice.patientForm">
  <Name>Girish</Name> 
  <Age>27</Age> 
  <AdharNo>1</AdharNo> 
  <MNo>MNo_0</MNo> 
  <Disease>Disease_0</Disease> 
</ns0:PatientForm>


If you do not send Schema_Medi msg within 1 min then you will get output as:
<?xml version="1.0" encoding="utf-8" ?> 
<ns0:Pat xmlns:ns0="http://Listen_Practice.schema_patient">
  <Name>Girish</Name> 
  <LastName>Patil</LastName> 
  <Age>27</Age> 
  <ANo>1</ANo> 
  <Disease>Disease_0</Disease> 
</ns0:Pat>

This is how Non-Uniform Sequential Convoy works..


We will implement next pattern in next blog, so till then "Keep Reading, Keep Improving"..
Enjoy..

7 comments:

  1. Just one question. what is the "Input Message" in Transform_1 shape?

    ReplyDelete
    Replies
    1. Actually I was confused that how first message will reach to the Construct shape. I found that all the messages reach to the construct shape we just need to specify the messages in source message in the map. But I still seek explaination on this.

      Delete
  2. Every one easily understand

    ReplyDelete
  3. Every one easily understand

    ReplyDelete
  4. Every one easily understood---Srinivasulu Sareddy

    ReplyDelete
  5. can you send me the project on my mail id- anishsingh0302@gmail.com

    ReplyDelete