Tuesday 11 March 2014

Filters on Receive Shape -- Biztalk Server 2010

We all know, we can have filters on the Send ports. Those filters are used to make subscription on send port. Filter on the sent port are used to handle/manipulate the outbound flow.

But then what about inbound flow? Is there any way by which my orchestration will pick only those messages which fulfil the condition and ignore the rest of messages?

To do so we have some options available such as to use decide shape, to implement Buisness Rule Engine but those options handles the messages in the orchestration. But, We want something by which messages which satisfy our condition, only those should have reached to orchestration.

Solution is "Filters on Receive Shape"

What is receive shape?
Receive shape is one of the shape provided in Biztalk Orchestration toolbox. In almost all of the orchestration, this is the start of process. It initiates the orchestration. We have to bind the receive shape with expected message type, so that it will subscribes to specified messages only.

In message box, whenever any message comes in, Messaging agent checks for the subscribers for that message. Messaging agent does that by matching the messagetype(target namespace#rootnode) of message with all the current available subscribers. If it finds any match, agent sends copy of message to that subscriber and delete the message from messagebox once it is delivered to subscriber.

So because of this, all the messages with required message type get passed to orchestration.

Suppose we have to create solution for below scenario:

Problem Description :
Suppose we having a process in which we receive orders from say customer ABC. We can process only those orders which are having Price less than 1000. If order price is greater than 1000 then we need to send it to Management dept which will do the further processing on it.

Solutions:
As I said earlier we can achieve this in number of ways, we will see how to do this with the help of filter on receive shape.

Will show you how to create solution for above problem.

Lets start..
Create a biztalk project in Visual Studio 2010.Name it OrderProcess_Filter.
Create two schemas OrderRequest.xsd and PO.xsd




Note : You need to Promote the OrderRequest/Price. We need to do that because we want to set condition in Receive shape based on that field. When you promote the field, Biztalk will create property schema automatically.

Then, create a map which will convert OrderRequest To PO. Name it OrderToPO.btm.


Create a orchestration name it POFilter_process. Add shapes in the orchestration as shown below:



Create below two messages:
msg_inputOrder  --- Message Type OrderProcess_Filter.OrderRequest
msg_outputPO    --- Message Type OrderProcess_Filter.PO

Configure the shapes in Orchestration as suggested below:
Receive_Order(Receive shape) is configured with the message msg_inputOrder. It will activate the orchestartion (Activate property is True)

ConstructPO(ConstructMessage shape) will have transform shape in it. It will transform msg_inputOrder to msg_outputPO. It will use the map OrderToPO.btm,  which we have already created.

Send_PO (Send Shape) is configures to send message of type msg_outputPO to the send port.

Configure Receive Port_ReceiveOrder and port_SendPO.

Now, go to Receive_Order Properties -> Filter Expression.
Click on the Ellipsis. Filter Expression Window will come up. In that select the property on which you want to set the condition/filter. In our case it is OrderProcess_Filter.PropertySchema.Price.
Select aprropriate Operator. We will use use ">"
Specify the constant value in Value column. We will use 1000.

Thats all we need to do, to add the filter on receive shape.
Now Build, deply the solution.

Create physical ports in the Biztalk Server 2010. We will need one receive port and one send port. Create/Configure it.

Ok then all configuration is done now, and we are ready to test the solution..

First we will test with below sample order
<ns0:OrderReq xmlns:ns0="http://OrderProcess_Filter.OrderRequest">
  <OrderID>OrderID_100</OrderID> 
  <OrderDate>1999-05-31</OrderDate> 
  <Currency>USD</Currency> 
  <Price>900</Price> 
</ns0:OrderReq>

Create sample file with above data and place it in the receive location.File will get picked up, check the Destination folder. You will get file with below contents:

<?xml version="1.0" encoding="utf-8"?>
<ns0:PO xmlns:ns0="http://OrderProcess_Filter.PO">
 <POID>OrderID_100</POID>
 <PO_Price>900</PO_Price>
</ns0:PO>

So far so good, order with price less than 1000 is picked up by the orchestartion. Now lets try one order with price more then 1000. Use below content:

<ns0:OrderReq xmlns:ns0="http://OrderProcess_Filter.OrderRequest">
  <OrderID>OrderID_101</OrderID> 
  <OrderDate>1999-05-31</OrderDate> 
  <Currency>USD</Currency> 
  <Price>1100</Price> 
</ns0:OrderReq>

File will get picked up, check destination folder, you will not get anything over there. So this means that this file did not get picked by our orchestration. In other words message box did not found any subscriber for this message. You will see this order in Suspended State in Biztalk Server Console Admin.


We wanted to send orders with price more than 1000 to administration dept(say to folder Administration). So to do that create one more physical port which will have filter in place like below:



Now test the sample with more than 1000 price again. You will get as is message in the Administration folder. That is because it did not get process through orchestration it was sent directly to Send Port.

This is how we implement filter on Receive shape.

This is it for now.. Will back with some more next time..

Till then Enjoy..

Thursday 6 March 2014

Call Orchestartion Shape in Biztalk

Most of the programming languages provides a way to do nested coding. By that we can define the a block of code which is generic and may be required number of times. Once we have that defined bunch then we just need to call it wherever we want.
For example:
A()
{
   B();
}

B()
{
.
.
.
}

As you can see in above example A and B are two functions which are nested. Function A call Function B. When execution of called function(B) gets started execution of calling function(A) goes on hold. Calling function resumes it execution after completing the called function.

We have same concept in Biztalk also, we can achieve this through Call Orchestration shape in the given toolbox.
In this blow we will do following things:
Understand what is Call Orchestration.
How to Implement it(with suitable example).
Dessert.

So lets start,

What is Call Orchestration??
We can add nested Orchestration in the Biztalk. Call Orchestration shape allows us to achieve that.
We can Call other Orchestration synchronously, which means calling Orchestration waits till  called orchestration's execution gets complete.
This feature of Biztalk helps programmers to reuse the common orchestration workflow patterns across Biztalk projects.

We can pass on parameters while calling the orchestration. Parameters can be like Message, variable, port reference, role links, correlation set.




How to Implement it(with suitable example):

I have created a demo application, which uses the Call Orchestration.
Below are the steps that I  followed:
Create a Biztalk Project in Visual Studio 2010 name it "Orc_Calling".

Add one simple schema into it.(Make Price as a distinguishable field, also make sure you specify its data type as int) name it "Outer_Schema.xsd"



Then Add couple of Orchestrations in the project
1)InnerOrch.odx -- It will be the common orchestration that we will call from other orchestration.



Short description of InnerOrch.odx --

Create two Orchestration Parameters(New Message Parameter)
1)input_MsgPara
2)output_MsgPara

This orchestration is designed to check if Price of message it receive is above 500 or not.
input_MsgPara.Price > 500

We have used Construct shape which contains MessageAssignment shape. In this we set the element Status of the message, according to the Price(decide shape branches).

Below are the statement that we have in the Message Assignment:
output_MsgPara = input_MsgPara;
xpath(output_MsgPara, "//Status") = "Expensive Product";

and in other shape we have

output_MsgPara = input_MsgPara;
xpath(output_MsgPara, "//Status") = "Non-Expensive Product";

2)OuterOrch.odx -- It will be the mail orchestration that we will call to other orchestration.



Short descrption of OuterOrch.odx --  We receive a message from Receive port, then we use Call Orchestration shape to call the innerOrch orchestration.Its result is then passed to Send port.

Create two Messages of schema Outer_Schema:
1)inputMsg
2)outputMsg


Configuration of the Call Orchestration:
Right click the Call Orchestration shape and select Configure.
In Call Orchestration Configuration, select the innerOrch orchestration, and pass the two messages we have created.

Thats All we need to implement the Call Orchestration.
Build it, deploy it and Test it(Will not cover those steps here, all these steps are same as we did for other applications).

Dessert:

We can even call the orchestration from other projects.
To do that, all we need is to follow couple of simple steps:
1)set the access modifier of the (to be)called orchestration to "public". By Default orchestrations are having modifier as "internal".
2)We Need to add the reference of the project having (to be)called orchestration, in the required project.

After that you can configure the Call Orchestration in the same way as we did earlier.

**Difference Between Call and Start Orchestration**
As we know, for every orchestration Biztalk assigns a thread to it.

Start and Call orchestration differs in following ways:
1) Calling Orchestration uses same thread to execute the another orchestration.
whereas Start Orchestration, Biztalk creates new thread to execute the other orchestration.

2) Call orchestration returns the control after its execution to the calling orchestration, hence it is a synchronous way.
whereas in Start Orchestration, starts the execution in non deterministic way, hence it is a synchronous way.

3) Call Orchestration Reduces the latency, as message does not go via messagebox.
whereas Start Orchestration increases the latency as message travels via message box.