前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >不需要Orchestration,通过Pipeline设定动态发送端口属性

不需要Orchestration,通过Pipeline设定动态发送端口属性

作者头像
阿新
发布2018-04-12 16:50:10
7240
发布2018-04-12 16:50:10
举报
文章被收录于专栏:c#开发者c#开发者

不需要Orchestration,通过Pipeline设定动态发送端口属性

通常情况下使用动态发送端口,需要Orchestration中使用表达式(Expression)指定具体的发送端口目的地址Port_1(Microsoft.XLANGs.BaseTypes.Address) = http://www.tradingpartner.com/receive.ashx 具体的地址可以根据传入的Message通过xpath表达式或是Promote属性获取,但是每个流程只能接收制定的Schema消息,如果想做一个通用的根据消息路由就不是很方便了。

实际情况是这样,有100个 不同的Schema,需要根据具体的消息实例的内容进行路由,具体的地址存放在“路由表”中,可以动态维护,一开始通过Orchestration,ReciveMessage的类型定义为通用的XmlDocument处理,在流程中通过xpath获取值后再去找“路由表”中对应的地址,设定动态发送端口地址。

这样做很显然效率很差,而且不规范,容易冲突

现在可以直接通过自定义开发receivepipeline组件,在pipeline执行时把需要的地址通过属性升级(promote)方式赋值,这样动态发送端口就可以直接根据具体属性值进行发送到指定的目的地。

注意:动态发送端口只能订阅到具有promote OutboundTransportType 和OutboundTransportLocation 属性的消息,如果以上两个属性没有升级,只是通过ReceivePortName或其他属性是无法订阅到消息的。

代码:

IBaseMessageContext context = inmsg.Context;

IBaseMessagePart bodyPart = inmsg.BodyPart;

Stream originalStrm = bodyPart.GetOriginalDataStream();

string inval = string.Empty;

string outboundaddress = string.Empty;

string[] fixstr;

            inval = Convert.ToString(context.Read(this._PropName, this._PropNamespaces));

if (string.IsNullOrEmpty(inval))

            {

//inval = GetInMessageValue(originalStrm);

            }

//outboundaddress = this.GetTransportLocation(inval);

            outboundaddress = @"msmq://.\private$\mq1";

if (outboundaddress.IndexOf("://") > 0)

            {

                fixstr = outboundaddress.Split(':');

this._PropTransportType = fixstr[0];

int firstidx = outboundaddress.IndexOf("//");

                outboundaddress = outboundaddress.Substring(firstidx + 2);

            }

if (this._PropTransportType.ToLower().Trim() == "msmq")

            {

                context.Promote("Transactional", "http://schemas.microsoft.com/BizTalk/2003/msmq-properties", this._PropTransactional);

                context.Promote("TimeOut", "http://schemas.microsoft.com/BizTalk/2003/msmq-properties", 4);

                context.Promote("TimeOutUnits", "http://schemas.microsoft.com/BizTalk/2003/msmq-properties", "Days");

            }

            context.Promote("OutboundTransportType", "http://schemas.microsoft.com/BizTalk/2003/system-properties", this._PropTransportType);

            context.Promote("OutboundTransportLocation", "http://schemas.microsoft.com/BizTalk/2003/system-properties", outboundaddress);

if (!string.IsNullOrEmpty(this._PropSPID.Trim()))

                context.Promote("SPID", "http://schemas.microsoft.com/BizTalk/2003/system-properties", this._PropSPID);

            bodyPart.Data = originalStrm;

            pc.ResourceTracker.AddResource(originalStrm);

return inmsg;

这样做自然性能会提高很多,方便维护

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-01-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档