gpt4 book ai didi

azure - Windows Workflow 4 关联查询在实例 key 计算中包含网站实例名称并失败

转载 作者:行者123 更新时间:2023-12-02 07:41:59 26 4
gpt4 key购买 nike

我正在尝试在 Azure 上托管一个长时间运行的工作流服务,但我遇到了关联问题。
我已将 timeToUnload 和 timeToPersist 设置为 0,并且在工作流程中勾选了“发送前保留” - 这不是持久性问题,而是与实例键的计算方式有关。

当一台 Web 服务器启动工作流,而另一台 Web 服务器尝试对该工作流执行另一操作时,它会失败并显示

System.ServiceModel.FaultException: The execution of an InstancePersistenceCommand was interrupted because the instance key '12e0b449-7a71-812d-977a-ab89864a272f' was not associated to an instance. This can occur because the instance or key has been cleaned up, or because the key is invalid. The key may be invalid if the message it was generated from was sent at the wrong time or contained incorrect correlation data.

我使用wcf服务诊断来深入研究这个问题,我发现这是因为实例 key 的计算包括网站实例名称,因此给定的工作流实例只能从实例化它的同一台计算机(因为 Azure 在每个角色实例上设置了不同的网站实例名称)。

为了解释一下,当我创建工作流的新实例时,我有一个事件获取工作流实例 Guid,然后返回该 guid,并使用相关初始值设定项来设置相关句柄。

我已在 web.config 中启用服务跟踪,因此在服务跟踪查看器中,当我实例化工作流的新实例时,我可以看到以下情况发生;

<ApplicationData >
<TraceData >
<DataItem >
<TraceRecord Severity ="Information" Channel="Analytic " xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord ">
<TraceIdentifier >225</ TraceIdentifier>
<Description >Calculated correlation key '496e3207-fe9d-919f-b1df-f329c5a64934' using values 'key1:10013d62-286e-4a8f-aeb2-70582591cd7f,' in parent scope '{/NewOrbit.ExVerifier.Web_IN_2_Web/Workflow/Application/}Application_default1.xamlx'.</Description >
<AppDomain >/LM/W3SVC/1273337584/ROOT-1-129811251826070757</AppDomain >
</TraceRecord >
</DataItem >
</TraceData >
</ApplicationData >

重要的一行是:

Calculated correlation key '496e3207-fe9d-919f-b1df-f329c5a64934' using values 'key1:10013d62-286e-4a8f-aeb2-70582591cd7f,' in parent scope '{/NewOrbit.ExVerifier.Web_IN_2_Web/Workflow/Application/}Application_default1.xamlx'.

此特定工作流实例的 Guid 为 10013d62-286e-4a8f-aeb2-70582591cd7f,因此工作流引擎根据 496e3207-fe9d-919f- 计算“实例 key ” b1df-f329c5a64934。我可以在 [System.Activities.DurableInstancing].[InstancesTable] 中看到带有 guid 的工作流实例,并且可以在 [System.Activities.DurableInstancing].[KeysTable] 中看到实例 key 。到目前为止,一切都很好,如果同一台服务器稍后调用同一工作流程,一切都会正常。但是,如果不同服务器尝试访问工作流程,我会收到上面提到的相关错误。再次查看诊断跟踪,我可以看到:

<TraceData >
<DataItem >
<TraceRecord Severity ="Information" Channel="Analytic " xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord ">
<TraceIdentifier >225</ TraceIdentifier>
<Description >Calculated correlation key '12e0b449-7a71-812d-977a-ab89864a272f' using values 'key1:10013d62-286e-4a8f-aeb2-70582591cd7f,' in parent scope '{/NewOrbit.ExVerifier.Web_IN_5_Web/Workflow/Application/}Application_default1.xamlx'. </Description >
<AppDomain >/LM/W3SVC/1273337584/ROOT-1-129811251818669004</AppDomain >
</TraceRecord >
</DataItem >
</TraceData >

重要的一行是

Calculated correlation key '12e0b449-7a71-812d-977a-ab89864a272f' using values 'key1:10013d62-286e-4a8f-aeb2-70582591cd7f,' in parent scope '{/NewOrbit.ExVerifier.Web_IN_5_Web/Workflow/Application/}Application_default1.xamlx'.

正如您所看到的,传入的是相同的 Guid,但系统在计算实例 key 时包含了网站实例的名称,因此最终得到了完全不同的实例 key 。

我创建了一个全新的项目来测试这个问题,并发现了完全相同的问题。我觉得我一定是做了一些非常简单的错误,因为我找不到其他人有同样的问题。

最佳答案

几个月后,我找到了解决这个问题的方法。根本问题是 Azure 在每个角色实例上为网站命名不同;该网站不是“默认网站”,而是类似 NewOrbit.ExVerifier.Web_IN_0_Web 的名称(为您的 Web 项目指定了 NewOrbit.ExVerifier.Web 的命名空间)。工作流使用网站名称作为用于计算实例 key 的算法的一部分,因此出现了问题。

解决方案非常简单,在角色启动期间重命名网站,以便在所有实例上调用相同的名称。解决根本问题而不是处理后果,如此明显,我第一次从未见过它。

以下是您可以执行此操作的方法(大致基于此:http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx)

将 powershell 配置为具有提升的访问权限,以便您可以在配置 IIS 后进行更改:

ServiceDefinition.csdef中添加启动任务:

<ServiceDefinition name="WasInAzure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole1">
...
<Startup>
<Task commandLine="setup\startup.cmd" executionContext="elevated" />
</Startup>
</WebRole>
</ServiceDefinition>

Setup\Startup.cmd 应包含以下内容:

powershell -command "set-executionpolicy Unrestricted" >> out.txt

将角色 OnStart 配置为具有管理员权限

ServiceDefinition.csdef中添加以下内容:

<ServiceDefinition name="WasInAzure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole1">
...
<Runtime executionContext="elevated" />
</WebRole>
</ServiceDefinition>

创建 powershell 脚本来重命名网站

创建一个setup\RoleStart.ps1文件:

write-host "Begin RoleStart.ps1"
import-module WebAdministration
$siteName = "*" + $args[0] + "*"
Get-WebSite $siteName | Foreach-Object {
$site = $_;
$siteref = "IIS:/Sites/" + $site.Name;
try {
Rename-Item $siteref 'MyWebSite'
write-host $siteName + " was renamed"
}
catch
{
write-host "Failed to rename " + $siteName + " : " + $error[0]
}
}
write-host "End RoleStart.ps1"

(将 MyWebSite 替换为您希望在所有服务器上调用该网站的任何内容)。

在角色启动时运行 RoleStart.ps1:

在网站项目的根目录中创建或编辑 WebRole.cs 并添加以下代码:

public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
var startInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = @".\setup\rolestart.ps1",
RedirectStandardOutput = true,
UseShellExecute=false,
};
var writer = new StreamWriter("out.txt");
var process = Process.Start(startInfo);
process.WaitForExit();
writer.Write(process.StandardOutput.ReadToEnd());
writer.Close();
return base.OnStart();
}
}

应该就是这样。如果您启动多个 Web 角色实例并使用 RDP 连接到它们,您现在应该能够看到该网站在所有实例上的调用方式相同,因此工作流持久性有效。

关于azure - Windows Workflow 4 关联查询在实例 key 计算中包含网站实例名称并失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10536983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com