发送适配器操作

发送适配器可以执行以下操作:

  • 重新提交:void Resubmit(IBaseMessage msg, DateTime timeStamp)。 在消息上发生传输失败后,适配器在适当时重新提交它。 这是基于每条消息调用的。 如果一批消息未成功提交,适配器必须确定导致失败的消息,并重新提交那些未导致批处理失败的消息,分别调用Resubmit。 本主题末尾提供了有关如何在调用 Resubmit 时保留消息上下文属性值的信息。

  • 移动到下一个传输:void MoveToNextTransport(IBaseMessage msg)。 如果在发送操作过程中消息失败,并且其重试已用尽,适配器可以将消息发送到下一个配置的传输通道进行重新传输。

  • 暂停:void MoveToSuspendQ(IBaseMessage msg)。 如果未配置其他备用传输,适配器会将发送失败的消息移动到挂起队列。 本主题末尾提供了有关如何在调用 Suspend 时保留消息上下文属性值的信息。

  • 删除:void DeleteMessage(IBaseMessage msg)。 适配器在 BizTalk Server 收到其成功传输的通知后删除消息。 删除消息会告知 BizTalk Server 适配器已完成该消息。 通常,SubmitResponse操作与它相关联的Delete操作在同一个批处理中完成。

  • 提交响应:void SubmitResponseMessage(IBaseMessage solicitMsgSent、IBaseMessage responseMsgToSubmit)。 适配器将响应提交到待返回 BizTalk Server 的批处理中。 此作包括调用中的原始消息以及响应,以便 BizTalk Server 可以关联它们。

  • 取消响应:void CancelResponseMessages(字符串 correlationToken)。 如果在提交批处理之前需要取消发送响应消息,将使用 CancelResponseMessages 方法,并传入要删除的关联响应消息的相关令牌。

    对消息调用 ResubmitSuspend 时,可能需要保留某些消息上下文属性的值。 可以通过以 XML 格式保存属性值来实现此功能。 重新提交或挂起消息时,相应的属性在消息上下文中仍然可用。

    以下 XML 字符串描述存储信息的格式:

<PropertiesToUpdate>  
<Property name="StringProperty" nameSpace="http://MyNamespace1" vt="8">SomeString</Property>  
<Property name="IntProperty" nameSpace="http://schemas.microsoft.com/BizTalk/2005/test-properties" vt="3">4</Property>  
<Property name="BoolProperty" nameSpace="http://schemas.microsoft.com/BizTalk/2005/test-properties" vt="11">0</Property>  
</PropertiesToUpdate>  

此 XML 字符串由以下代码生成:

private string GetPropsToUpdateXml(int nextRetryAttempt)  
{  
string result = "<PropertiesToUpdate><Property name=\"RetryAttempts\" nameSpace=\"http://schemas.microsoft.com/BizTalk/2005/test-properties\" vt=\"3\">" + nextRetryAttempt.ToString() + "</Property></PropertiesToUpdate>";  
return result;  
}  

然后,使用此代码将此字符串保存到消息上下文:

Message.Context.Write("PropertiesToUpdate", "http://schemas.microsoft.com/BizTalk/2003/system-properties", GetPropsToUpdateXml(++retryAttempt));  

重新提交消息后,适配器可以使用以下代码行读取此属性:

propValue = inmsg.Context.Read("RetryAttempts", "http://schemas.microsoft.com/BizTalk/2005/test-properties");