如何使用BizTalk的MSMQ适配器设置MSMQ消息扩展?

sch*_*ack 6 biztalk msmq

我们使用BizTalk Server通过MSMQ发送消息.接收系统要求每条消息都将扩展属性设置为guid(作为字节数组).MSDN文档的MSMQMessage的扩展属性在这里(在.NET)和这里.

在.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();
}
Run Code Online (Sandbox Code Playgroud)

但是,BizTalk的MSMQ适配器不会将消息扩展显示为可以设置的内容(请参阅MSDN上的适配器属性列表).我还反编译了BizTalk 2013附带的Microsoft.BizTalk.Adapter.MSMQ.MsmqAdapter程序集,并且找不到对扩展属性的引用.

如何设置BizTalk发送的MSMQ消息的扩展名?如果可能的话,我宁愿不必创建自定义适配器,因为这需要大量的开销和持续的维护.

par*_*awk 3

你看到这篇文章了吗?http://msdn.microsoft.com/en-us/library/aa560725.aspx

本文展示了如何以编程方式设置 MSMQ 接收位置;此外,它公开了对可能需要但默认 BizTalk 适配器未显示的辅助属性的访问 - (例如扩展)。

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);
Run Code Online (Sandbox Code Playgroud)

编辑:

将 BizTalk MSMQ 适配器代码反编译到接口级别后,我没有看到使用默认适配器执行此操作的方法。由于适配器是密封的,因此也无法延长。

我发现的唯一其他选择是

  1. 创建自定义适配器(如您已经列出的)
  2. 技巧 1:将数据放置在 MSMQ 适配器可访问的属性中(例如标签),使用外部进程拦截消息,并在那里进行转换。
  3. hack 2:使用已编写的自定义适配器来调用 powershell 脚本并在该脚本中执行必要的转换/传输。http://social.technet.microsoft.com/wiki/contents/articles/12824.biztalk-server-list-of-custom-adapters.aspx#BizTalk_PowerShell_Adapter
  4. hack 3:重新定义需求。例如,让接收者将所需字段从“扩展”更改为可用的字段(例如“标签”)。
  5. hack 4:尝试找到一种通过 WCF-MSMQ 适配器发送消息的方法。http://msdn.microsoft.com/en-us/library/system.servicemodel.netmsmqbinding.aspx

编辑:( 您不应该设置扩展属性的原因)

扩展属性用于将大消息链接在一起,如果总消息大小超过 4MB,这些消息会在传输过程中出现碎片。这是在幕后完成的,如果被规避,可能会导致大消息损坏。

要参与大型消息交换,消息队列计算机必须安装 Mqrtlarge.dll 文件,并且消息队列应用程序应使用附加 API。否则,完整的消息将被分成碎片。

BizTalk 2004 大消息扩展文档

BizTalk 2010 大消息扩展文档