如何解决为什么 BizTalk 2016 会杀死自定义管道组件线程?
我有一个 BizTalk 自定义管道组件,用于写入 SFTP 文件(使用 SSH.net),由 SFTP (WinSCP) 接收位置触发。
重试中的代码偶尔(大约有一半的时间)既未命中“成功”,也未命中日志捕获块,并且管道内不会发生进一步的处理。我认为这意味着线程已被销毁。
我稍后添加了 Retry 代码以使其尝试几次,但随着线程被破坏,我并不总是成功或 3 次失败。
什么可能导致 BizTalk 2016 出现这种行为?
public void Archive(byte[] content,string archivePath,string userName,string password,string serverAddress,string sshHostKeyFingerprint)
{
Retry(3,() =>
{
try
{
using (var sftpClient = new SftpClient(serverAddress,userName,password))
{
if (!string.IsNullOrWhiteSpace(sshHostKeyFingerprint))
{
sshHostKeyFingerprint = sshHostKeyFingerprint.Split(' ').Last();
sftpClient.HostKeyReceived += delegate (object sender,HostKeyEventArgs e)
{
if (e.FingerPrint.SequenceEqual(ConvertFingerprintToByteArray(sshHostKeyFingerprint)))
e.CanTrust = true;
else
e.CanTrust = false;
};
}
sftpClient.Connect();
sftpClient.WriteAllBytes(archivePath,content);
sftpClient.Disconnect();
LogInfo($"Success");
}
}
catch (Exception exception)
{
// show the bad path for "No such file" errors
throw new InvalidOperationException($"Failed to create file '{archivePath}'",exception);
}
});
}
private void Retry(int maxAttempts,Action action)
{
int attempt = 1;
while (attempt <= maxAttempts)
{
try
{
action();
break; // success
}
catch (Exception exception)
{
LogWarning($"Attempt {attempt} Error: {exception.ToString()}");
if (attempt == maxAttempts)
throw; // final attempt exception propagated
}
finally
{
attempt++;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。