Random File Message Creator Component for LoadGen

18 June 2009

LoadGen is my favorite tool to perform automatic testing in BizTalk. It is easy to configure and extensible.

When I want to mimic the characteristics of the BizTalk production environment in a test lab as close as possible, LoadGen is the way to go. The load, in terms of number of messages per time unit, can be easily set and tuned by changing values in the LoadGen configuration file.

As said before I want to get as close as possible to the production environment. This also means that I want to use messages that are close to (or better equal to) the production environment.

LoadGen comes with template functionality that you can use to change the message content before passing the message on to BizTalk. This functionality is a bit limited to my opinion.

What I wanted to do is copy a batch of messages from production and use them in my test. To be able to do this I had to write a simple ‘MessageCreator’ component for LoadGen.

A ‘MessageCreator’ is a component that implements the ‘IMessageCreator’ interface found in LoadGen.dll. The ‘MessageCreator’ is called whenever the LoadGen run-time needs a new message. Its task is to create the message and pass it back to the run-time. After that the run-time passes the message to the configured transport components. (Actually the ‘MessageCreator’ fills an internal queue from which other threads dequeue messages).

The default ‘MessageCreator’ that comes with LoadGen is only capable of using a single file for input so I created a new one that:

  • - builds a list of files in a specific folder
  • - random picks a file from the list
  • - uses this file to create the new message

The code is straightforward. The ‘CreateNewMessage’ is the main method responsible for creating the message:

image

It calls two helper methods ‘CreateFileList’ and ‘GetFileFromList’:

image

I used the following LoadGen configuration file for my test:

image

The ‘MessageCreator’ is put in synchronous mode to make sure it create unique messages for all the client threads.

The ‘SrcFilePath’ path contains a pointer to a file where I actually only need the folder. Unfortunately LoadGen fails when there is no file at the end of the path. Internally I only use the path. The same applies to ‘TemplateFilePath’. I don’t need that here but the run-time for this setting.

In this sample I skipped the implementation of the ‘OptimizeFileSizeLimit’ property to keep things simple. I also did not need in in my test. The ‘OptimizeFileSizeLimit’ can be configured in the configuration file and basically tells the LoadGen run-time whether or not it is dealing with a large messages. If this is the case the creation of the message might be performed in another, more optimized way. The samples provided with LoadGen use this to skip file transport component and directly stream from the message component.

 

Was promoted

15 June 2009

Ever wanted to know in a send pipeline if a property was promoted before? The BizTalk API comes with an object called ‘ContextPropertyType’ which you can use for this purpose.

I have a very simple schema and corresponding instance:

waspromoted_schema

waspromoted_schema_instance

Above message travels through BizTalk using the following path:

receive port -> orchestration -> send port

I defined the ‘Firstname’ element as promoted property to have it promoted by the out-of-the-box XmlReceive pipeline. After that the message is sent to the message box and picked up by the orchestration to do some processing. Next the orchestration will send the message to the message box again using a send shape. Finally the send port picks up the message and sends it to some URI using an adapter.

In the send port I used a custom pipeline containing a pipeline component with this code:

waspromoted_code

 After the message has been picked up by the send port the messaging engine will alter the context of the message. The ‘Firstname’ element that was promoted before is not promoted anymore now. To prove this I call the IsPromoted method for the specific property (see code above).

So what if you want to know if the property was promoted before? This is where the ContextPropertyType object comes in. Together with the ‘GetPropertyType’ method on the context object I’m able to find the status of the property.

Running this example shows the following output in DebugView:

waspromoted_debug_view

 As you can see the PropertyType has a value equal to ContextPropertyType.WasPromoted. In the above sample I used an orchestration in the middle but the same will also apply to messaging only scenarios.

Although I recently made use of this API while implementing a very simple repair and resubmit feature, there might not be so many real world scenarios where one would use this. At least I couldn’t think of many. (Suggestion? Ping me, please.).  Also be aware that is an undocumented feature for which the BizTalk help states it is for internal use only. This basically means Microsoft will not guarantee any backward compatibility for this when new versions or SPs are released.


Follow

Get every new post delivered to your Inbox.