首页 > 解决方案 > 为什么 BizTalk 2016 会杀死自定义管道组件线程?

问题描述

我有一个 BizTalk 自定义管道组件,它写入一个 SFTP 文件(使用 SSH.net),由 SFTP(WinSCP)接收位置触发。

重试中的代码偶尔(大约一半时间)既没有达到“成功”,也没有达到日志捕获块,并且管道内没有进一步的处理。我认为这意味着线程已被破坏。

我稍后添加了重试代码以使其尝试几次,但是随着线程被破坏,我并不总是成功或 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++;
                }
            }
        }

标签: sftpbiztalkssh.netwinscp-netbiztalk-2016

解决方案


推荐阅读