【问题标题】:How do I set the MSMQ Message Extension Using BizTalk's MSMQ Adapter?如何使用 BizTalk 的 MSMQ 适配器设置 MSMQ 消息扩展?
【发布时间】:2014-07-09 06:40:56
【问题描述】:

我们正在使用 BizTalk Server 通过 MSMQ 发送消息。接收系统要求每条消息都将扩展属性设置为 guid(作为字节数组)。 MSDN 记录了 MSMQMessage here 和(在 .NET 中)here 的 Extension 属性。

在.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 适配器不会将消息扩展显示为可以设置的内容(请参阅list of adapter properties on MSDN)。我还反编译了 BizTalk 2013 附带的 Microsoft.BizTalk.Adapter.MSMQ.MsmqAdapter 程序集,找不到对扩展属性的引用。

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

【问题讨论】:

    标签: msmq biztalk


    【解决方案1】:

    你看到这篇文章了吗? 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. hack 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:重新定义要求。例如。让接收者将必填字段从 Extension 更改为可用的内容(例如 Label)。
    5. hack 4: 尝试找到一种通过 WCF-MSMQ 适配器发送消息的方法。 http://msdn.microsoft.com/en-us/library/system.servicemodel.netmsmqbinding.aspx

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

    Extension 属性用于将大邮件链接在一起,如果总邮件大小超过 4MB,这些邮件在传输过程中会变得支离破碎。这是在幕后完成的,如果绕过可能会导致大型消息的损坏。

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

    BizTalk 2004 Large Message Extension Documentation

    BizTalk 2010 Large Message Extension Documentation

    【讨论】:

    • 这是一个以编程方式创建 MSMQ 发送端口的好工具,但不幸的是,我们仍然只能设置 MSMQ 适配器已经定义的“自定义属性”。它不允许我们添加额外的属性,例如消息扩展。
    猜你喜欢
    • 2020-04-13
    • 2014-08-17
    • 1970-01-01
    • 2012-03-02
    • 2018-01-03
    • 2011-05-28
    • 2010-12-03
    • 2014-08-21
    • 2016-01-21
    相关资源
    最近更新 更多