Sometime back, I wrote an article on CodeProject titled "Explaining the BizTalk Architecture to your Grandma". This article got me a lot of feedback for a real hands-on example, and I committed to it at that time. So this article is delivering on that note. The target audience for this article is a BizTalk beginner, and the article is going to address two simple scenarios based on Content Based Routing (CBR) where the messages are directly subscribed between send and receive ports using filters on the message box. The scenarios are explained below.
You would remember the port facility from the previous example. The example consisted of different packages/messages arriving and getting routed. In this case, the scenario is: there is a Receive Location where you get a file, and this needs to be copied to another folder on another machine (this could as well be another company location in Delhi connected through a company LAN).
Scenario 2 is an extension of scenario 1. Here, what has occurred is your company WAN had some outage at Delhi and you had this sudden requirement to move this file to an FTP server. You will shortly see how easy it is to make this change in BizTalk.
A bird's eye view of the steps
This is a brief of the steps:
- Define the Receive Port and Receive Location for the file.
- Define the Receive Location properties.
- Define the Send Port and configure the Port.
- Define the filter which connects the Receive Port and the Send Port.
- Start, enlist, deploy, and test our scenario 1.
- Create a new Send Port for scenario 2 using FTP as Transport.
- Configure this new Send Port and filters.
- Start, enlist, deploy, and test our scenario 2.
Getting down to business ..
I have broken down the activity into a series of logical steps.
Step 1: The BizTalk Explorer
In Visual Studio .NET, if you have BizTalk installed, press Ctrl-Alt-Z to bring up the BizTalk Explorer. You can open this from the View menu also.
Step 2: Creating the Receive Port and Receive Location
In the Explorer, expand your server node and right click on Receive Ports, and select Add Receive Port. In the next dialog box, select One-Way Port and click Next. In the dialog that appears, name our receive port
AtlanticExpress.Pickup, and click OK. This will create our receive port
AtlanticExpress.Pickup under Receive Ports.
Step 3: Creating and configuring the Receive Location
Right click on Receive Locations under the receive port
AtlanticExpress.Pickup that we just created, and on this new port, select Add Receive Location from the menu. In the dialog that appears, change the name to
AtlanticExpress.Pickup.Location, then select the transport type as
FILE from the list of available transport adaptors. Change the Receive Handler to
BizTalkServerApplication (if you have given some other name for your BizTalk installation, that will appear in the drop down). Change the Receive Pipeline to
Microsoft.BizTalk.DefaultPipelines.PassThruReceive. This means we are asking BizTalk to pass the file through without any processing like stripping Mime headers out or validating the party using our custom receive pipelines.
Now in the Address (URI) field, use the “...” button to configure the file transport details. Create a directory C:\AtlanticWareHouse\Pickup on your local machine and select that as the Receive Folder as shown below. Configure File Mask as *.*. This means we are setting the mask to pickup any files. We can set this as *.txt, *.csv, or MyCustom*.xml if we want more control on what is picked up. Leave other values on their default as shown below:
Step 4: Creating the Send port and configuring it
Now in the BizTalk Explorer, right click Send Ports and select Add Send Port. In the Create New Send Port dialog, choose Static One-Way Port (if not selected already) and click OK. In the Port Properties dialog, change the name to
AtlanticExpress.Send. In the tree control under Configurations >Transport > Primary, set the Transport Type to FILE. Click the "..." button. To configure the Address (URI) field, create a folder on your local machine C:\AtlanticWareHouse\Drop and set this as the Destination folder (note: this could be your company WAN location in Delhi, in which case you could say \\DelhiServer\Shared\Drop). In the FILENAME field, put %SourceFileName%. This is a macro which tells BizTalk to retain the original file name. (Note: if you want unique names, you could use %MessageID%. This will create a random GUID as the filename.) Leave the Copy mode as Create New and click OK.
Now, under Configurations > Send > General, set Send Pipeline to
Microsoft.BizTalk.DefaultPipelines.PassThruTransmit. This means we are telling BizTalk to pass the whole file through without any extra processing. This is where we can use custom pipelines to encrypt or sign a message if we want.
The next step is what connects the Receive and Send ports together using a filter. As I said, this is a CBR scenario. BizTalk promotes certain context properties about the file into the message context associated with the file. The send port subscribes using this information. You could as well use your own custom fields here to decide routing. To do this, under Configurations > Filters & Maps > Filters, set
AtlanticExpress.Pickup as shown below:
Step 5: Revving it up
OK, now we have the basic stuff in place. We need to enable our Receive Location. Right click on AtlanticExpress.Pickup.Location and select Enable from the menu.
Next, in the Send Port AtlanticExpress.Send, right click and select Start. This will first Enlist and then Start the Port.
Now, drop a file in your pickup directory and you will see it disappear in a few seconds (wait for a minute or so the first time so that subscriptions get loaded), and look in your Drop directory. If you find the file there, congratulations you just completed your first BizTalk Hello World . Welcome to BizTalk!
Step 6: Modifying your example for Scenario 2 to use FTP
Now, remember, our scenario 2 is to modify this drop location from a file drop to an FTP drop. So, go back to BizTalk Explorer and right click AtlanticExpress.Send and Stop the Port, and then right click again and select Unenlist. Double click on the Port to open the configuration window. Now, under Configurations > Transport > Primary, set Transport Type to FTP. Click Address URI and it opens the dialog box below, and set the following properties: set Server to your server name (ftp.yoursite.com) or IP (say 220.127.116.11), set UserName (your FTP user name), set the Password for your FTP user, set Folder as the folder you want the file to be dropped, say /wwwroot/test. Set Target File Name as %SourceFileName%. Click OK.
Now, you will come back to the Send Port properties and it should look like as in the figure below. Click OK to come back to the Explorer.
Step 7: Testing the FTP scenario
Like in step 5 above, choose the Send Port AtlanticExpress.Send, right click and Enlist, and then Start. Now, go back to your drop folder and drop a file. Now log into your FTP location and browse to this directory. You should see your file there, and if you do, congrats you have completed scenario 2.
Points of Interest
You could modify this scenario in a lot of ways, You could, say, instead of modifying the Send Port, create a new Send Port and add both the Send Ports as a part of a Send Port Group which subscribes to the Receive Port. So the file will be dropped to both locations simultaneously. You can send the file over SMTP. The possibilities are endless. I will leave you to explore it. As a parting note, if you find any difficulty with the example, leave me a comment here, or ask me at this forum where I frequent more. You will also get a faster response as the forum has many BizTalkers.
- Version 1.0 - February 21, 2005.