无法通过 Visual Studio 代码在本地 运行 Azure Durable Function
Cannot run Azure Durable Function locally via Visual Studio Code
我按照教程 Visual Studio Code quickstart 并在本地创建了一个持久函数。当我的持久函数在启动函数
中执行 await client.startNew 时,我收到一条错误消息
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
错误信息如下:
Executed 'Functions.HttpTrigger' (Failed,
Id=84dc103d-bef9-4450-b4c6-9e612c6dc263) System.Private.CoreLib:
Exception while executing function: Functions.HttpTrigger.
System.Private.CoreLib: Result: Failure Exception: Error: write EPROTO
101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown
protocol:openssl\ssl\s23_clnt.c:827: Stack: Error: write EPROTO
101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown
protocol:openssl\ssl\s23_clnt.c:827:
at _errnoException (util.js:992:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:864:14).
我的环境:
- Azure 函数核心工具 (2.3.148)
- 函数运行时版本(2.0.12210.0)
- Node.js 8
这是我刚从教程中复制的代码。
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["post"]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
]
}
如何解决这个问题?
更新
自 npm package durable-functions
v1.1.3
以来,该问题已得到修复
你遇到了一个known issue。
This is due to current IWebHookProvider implementation, which causes the DurableOrchestrationClient class to use the wrong webhook URLs. The workaround is to set local environment variable WEBSITE_HOSTNAME to localhost:, ex. localhost:7071
如果设置env之前已经打开了VS Code,别忘了重启它以使新的env变量生效。
只是总结了我所做的,以防有人遇到同样的问题。
在Windows10
在终端输入指令设置环境变量
setx WEBSITE_HOSTNAME "localhost:7071"
关闭 vs code 并重新启动它
我按照教程 Visual Studio Code quickstart 并在本地创建了一个持久函数。当我的持久函数在启动函数
中执行 await client.startNew 时,我收到一条错误消息const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
错误信息如下:
Executed 'Functions.HttpTrigger' (Failed, Id=84dc103d-bef9-4450-b4c6-9e612c6dc263) System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger. System.Private.CoreLib: Result: Failure Exception: Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:827: Stack: Error: write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:827: at _errnoException (util.js:992:11) at WriteWrap.afterWrite [as oncomplete] (net.js:864:14).
我的环境:
- Azure 函数核心工具 (2.3.148)
- 函数运行时版本(2.0.12210.0)
- Node.js 8
这是我刚从教程中复制的代码。
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["post"]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
]
}
如何解决这个问题?
更新
自 npm package durable-functions
v1.1.3
你遇到了一个known issue。
This is due to current IWebHookProvider implementation, which causes the DurableOrchestrationClient class to use the wrong webhook URLs. The workaround is to set local environment variable WEBSITE_HOSTNAME to localhost:, ex. localhost:7071
如果设置env之前已经打开了VS Code,别忘了重启它以使新的env变量生效。
只是总结了我所做的,以防有人遇到同样的问题。
在Windows10
在终端输入指令设置环境变量
setx WEBSITE_HOSTNAME "localhost:7071"
关闭 vs code 并重新启动它