Azure / Azure/azure-webpubsub

How to Trigger Node Azure Functions WebPubSub Trigger Binding in for messages from Users locally?

Open
#828 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
147
Forks
96
Avg merge
19h 28m
Merged PRs (30d)
87

Description

Hello,

I want to create a serverless Client -> Azure Function for bi-directional communication using Azure Functions with the Azure WebPubSub Trigger binding "in" for user messages. I followed everything in the following tutorial https://learn.microsoft.com/en-us/azure/azure-web-pubsub/quickstart-serverless?tabs=javascript-v3 and am using Node for Azure functions with the Javascript v3 model specified on the linked article. I want to test this locally but the article never specified how this can be actually accomplished they just skip to deploying the function and testing it there...

Here's the basic view for how my client and subscriber look omitting the boilerplate code needed

CLIENT (JS):

```
let ws = new WebSocket(this.#url);
ws.onopen = function(){
ws.send("hello world");
}
ws.onmessage = (event) => {
console.log("NEW MESSAGE");
console.log({event});
};
```

Server (Node 18.x.x):

function.json

```
{
"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)"
}
}
```
I've been trying to invoke my trigger binding (folder is named test-user-event if it matters) via the line above

>
ws.send("hello world");

But nothing ever hits my local machine... I have checked over multiple issue points and everything I have set up seems correct according the latest documentation

My connection string variables are correct and point to an active WebPubSub resource I have In Azure

1. My azure functions works locally when using RESTful endpoints
2. I correctly connect to the WebSocket and the message Is sent
3. Both client and server are connected to the same hub
4. Set up the event handler on that hub to support tunnel:///runtime/webhooks/webpubsub

I am aware of the [https://www.npmjs.com/package/@azure/web-pubsub-tunnel-tool/v/1.0.0-beta](https://www.npmjs.com/package/@azure/web-pubsub-tunnel-tool/v/1.0.0-beta) Azure tunnel tool but isn't this only for when you have a persistent server such as Express? How do I accomplish this with Azure functions alone? The Client WebSocket sent method is a POST request how Is that supposed to hit my Azure WebPubSub trigger locally? Also I used the native browser WebSocket implementation for that client but is all this possible using the official Azure SDK as well via the SendEvent() method? https://www.npmjs.com/package/@azure/web-pubsub-client

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked serverless quickstart and the Azure Web PubSub tunnel tool documentation, then compare the reported function.json, index.js, and host.json with the local setup. Document how a Node Azure Function WebPubSub user-message trigger is invoked locally, including the event handler configuration and whether the browser client or SDK changes the flow. Done means the tutorial explains a reproducible local test path.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, javascript, node.js
Domain
backend, cloud, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.