Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the MSMQ Message Extension Using BizTalk's MSMQ Adapter?

Tags:

msmq

biztalk

We are using BizTalk Server to send messages via MSMQ. The receiving system requires that each message have the extension property set to a guid (as a byte array). MSDN documents the Extension property of the MSMQMessage here and (in .NET) here.

It is simple to set the extension property in .NET:

const string messageContent = "Message content goes here";
var encodedMessageContent = new UTF8Encoding().GetBytes(messageContent);

// Create the message and set its properties:
var message = new System.Messaging.Message();
message.BodyStream = new System.IO.MemoryStream(encodedMessageContent);
message.Label = "AwesomeMessageLabel";
// Here is the key part:
message.Extension = System.Guid.NewGuid().ToByteArray();

// Bonus! Send the message to the awesome transactional queue:
const string queueUri = @"FormatName:Direct=OS:localhost\Private$\awesomeness";
using (var transaction = new System.Messaging.MessageQueueTransaction())
{
    transaction.Begin();
    using (var queue = new System.Messaging.MessageQueue(queueUri))
    {
        queue.Send(message, transaction);
    }
    transaction.Commit();
}

However, BizTalk's MSMQ adapter does not surface the message extension as something that can be set (refer to the list of adapter properties on MSDN). I also decompiled the Microsoft.BizTalk.Adapter.MSMQ.MsmqAdapter assembly that ships with BizTalk 2013 and can find no reference to the extension property.

How can I set the extension of the MSMQ message sent by BizTalk? I would prefer to not have to create a custom adapter, if possible, as that requires a large amount of overhead and ongoing maintenance.

like image 397
schellack Avatar asked Sep 10 '13 17:09

schellack


People also ask

What is the BizTalk Server adapter for MSMQ?

With the BizTalk Server Adapter for MSMQ (the MSMQ adapter), you can send and receive messages to Microsoft Message Queuing (also known as MSMQ) queues using Microsoft BizTalk Server. The MSMQ adapter supports Message Queuing 4.0.

Is it possible to set the message extension in BizTalk 2013?

However, BizTalk's MSMQ adapter does not surface the message extension as something that can be set (refer to the list of adapter properties on MSDN ). I also decompiled the Microsoft.BizTalk.Adapter.MSMQ.MsmqAdapter assembly that ships with BizTalk 2013 and can find no reference to the extension property.

How to extend the MSMQ adapter?

The adapter can't be extended either as it is sealed. hack 1: Place the data in a property that IS accessible by the MSMQ Adapter (e.g. Label), intercept the message with an external process, transform it there. hack 3: Redefine the requirements.

What types of message queuing does the MSMQ adapter support?

The MSMQ adapter supports Message Queuing 4.0. The adapter works with transactional and non-transactional, public and private, and local and remote queues.


1 Answers

Did you see this article? http://msdn.microsoft.com/en-us/library/aa560725.aspx

The article shows how to programmatically set an MSMQ receive location; additionally, it exposes access to secondary properties that might be necessary but not shown by the default BizTalk adapter - (e.g. Extension) .

ManagementClass objReceiveLocationClass =
    new ManagementClass(
                    "root\\MicrosoftBizTalkServer",
                    "MSBTS_ReceiveLocation",
                    null);
// Create an instance of the member of the class
ManagementObject objReceiveLocation =
            objReceiveLocationClass.CreateInstance();

// Fill in the properties
objReceiveLocation["Name"] = name;
objReceiveLocation["ReceivePortName"] = port;
objReceiveLocation["AdapterName"] = adapterName;
objReceiveLocation["HostName"] = hostName;
objReceiveLocation["PipelineName"] = pipeline;
objReceiveLocation["CustomCfg"] = customCfg;
objReceiveLocation["IsDisabled"] = true;
objReceiveLocation["InBoundTransportURL"] = inboundTransport;

// Put the options -- creates the receive location
objReceiveLocation.Put(options);

EDIT:

After decompiling the BizTalk MSMQ adapter code down to the interface level, I don't see a way of doing this using the default adapter. The adapter can't be extended either as it is sealed.

The only other options I've found are

  1. Create a custom adapter (as you have already listed)
  2. hack 1: Place the data in a property that IS accessible by the MSMQ Adapter (e.g. Label), intercept the message with an external process, transform it there.
  3. hack 2: Use a custom adapter that is already written to call a powershell script and do the necessary transformation/transmission in that script. http://social.technet.microsoft.com/wiki/contents/articles/12824.biztalk-server-list-of-custom-adapters.aspx#BizTalk_PowerShell_Adapter
  4. hack 3: Redefine the requirements. E.g. get the receiver to change the required field from Extension to something that is available (e.g. Label).
  5. hack 4: Attempt to find a way to send the message via the WCF-MSMQ adapter. http://msdn.microsoft.com/en-us/library/system.servicemodel.netmsmqbinding.aspx

EDIT: (The reason why you SHOULDN'T set the extension property)

The Extension property is used to link large messages together which get fragmented in transport if the total message size is over 4MB. This is done under the covers and if circumvented can cause the corruption of large messages.

To participate in large message exchanges, the message queuing computer must have the Mqrtlarge.dll file installed, and the message queuing application should use the add-on APIs. Otherwise, complete messages will be fragmented.

BizTalk 2004 Large Message Extension Documentation

BizTalk 2010 Large Message Extension Documentation

like image 108
parrottsquawk Avatar answered Oct 19 '22 16:10

parrottsquawk