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..

No comments:

Post a Comment