功能
{
"disabled": false,
"bindings": [
{
"type": "webPubSubTrigger",
"direction": "in",
"name": "data",
"hub": "testhub",
"eventName": "message",
"eventType": "user"
}
]
}
index.js
module.exports = function (context, data) {
console.log('Request message data: ', data);
}
-host.json
{
"version": "2.0",
"extensions": {
"http": {
"routePrefix": ""
}
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.*, 4.0.0)"
}
}
我一直在尝试通过上述行调用我的触发绑定(如果很重要的话,文件夹命名为“测试用户事件”)
Ws.send(“ Hello World”);
但是什么都没有撞到我的本地机器...我已经检查了多个问题点,并且我设置的所有问题似乎都正确,根据最新文档
我的连接字符串变量是正确的,并指向我在azure中拥有的Active WebPubsub资源
使用RESTFULENPOINTS
时,我的Azure函数在本地起作用i正确连接到Websocket,并发送了消息设置该枢纽上的事件处理程序以支持隧道:/// Runtime/webhooks/webpubsub客户端和服务器都连接到同一枢纽
我知道
https://www.npmjs.com/package/@azure/web-pubsub-tunnel-tool/v/1.0.0.0.0.beta, Azure Tunnel工具,但这不是仅仅是因为您拥有持久服务器(例如Express)吗?我如何单独使用Azure功能来实现这一目标? WS发送方法是邮政请求,应该如何在本地击中我的Azure WebPubSub触发器? 我还为该客户端使用了本机浏览器Websocket实现,但是还可以使用官方的Azure SDK?
https://www.npmjs.com/package/@azure/web-pubsub-client -local.settings.json:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"WebPubSubConnectionString":"<WebPubSub_ConnectionString>"
}
}
func start
Azure Functions Core Tools
Core Tools Version: 4.0.6821 Commit hash: N/A +c09a2033faa7ecf51b3773308283af0ca9a99f83 (64-bit)
Function Runtime Version: 4.1036.1.23224
[2025-02-05T12:22:15.200Z] Worker process started and initialized.
Functions:
index: [GET,POST] http://localhost:7071/api/index
negotiate: http://localhost:7071/api/negotiate
message: webPubSubTrigger
For detailed output, run func with --verbose flag.
[2025-02-05T12:22:20.155Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-02-05T12:23:19.360Z] Executing 'Functions.negotiate' (Reason='This function was programmatically called via the host APIs.', Id=393ae9d8-f952-4f73-b5ea-288a973e560a)
[2025-02-05T12:23:19.560Z] Executed 'Functions.negotiate' (Succeeded, Id=393ae9d8-f952-4f73-b5ea-288a973e560a, Duration=233ms)
http://localhost:7071/api/negotiate: