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

6
我们正在使用BizTalk Server通过MSMQ发送消息。接收系统要求每个消息都设置扩展属性为GUID(作为字节数组)。MSDN文档了MSMQMessage的Extension属性here和(在.NET中)here
在.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();
}

然而,BizTalk的MSMQ适配器并不将消息扩展作为可以设置的内容呈现(请参阅MSDN上适配器属性列表)。我还反编译了随BizTalk 2013一起提供的Microsoft.BizTalk.Adapter.MSMQ.MsmqAdapter程序集,但未找到扩展属性的引用。
如何设置BizTalk发送的MSMQ消息的扩展?如果可能的话,我希望不必创建自定义适配器,因为这需要大量的开销和持续的维护。
1个回答

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);

编辑:

将BizTalk MSMQ适配器代码反编译到接口级别后,我没有找到使用默认适配器进行此操作的方法。该适配器也无法扩展,因为它是密封的。

我找到的唯一其他选项是:

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

编辑: (为什么您不应该设置扩展属性)

Extension属性用于链接在传输中被分段的大型消息,如果总消息大小超过4MB,则会在其下面执行此操作。这是在底层完成的,如果规避了此操作,可能会导致大型消息的损坏。

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

BizTalk 2004大型消息扩展文档

BizTalk 2010大型消息扩展文档


这是一个非常巧妙的工具,可以通过编程方式创建MSMQ发送端口,但不幸的是,我们仍然只能设置MSMQ适配器已定义的“自定义属性”。它不允许我们添加其他属性,例如消息扩展。 - schellack

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接