Running SignalR Service with Azure function not working

634 Views Asked by At

I'm trying to run SignalR Service using azure functions with nodeJS to be able send messages to react. doc

Actually I just want to set up backend services ( SignalR + send messages functions ) locally.

For that I have created SignalR function:

module.exports = async function (context, req, connectionInfo) {
    console.log(connectionInfo)
    context.res.body = connectionInfo;
};

in function.json

{
    "bindings": [
    {
        "authLevel": "anonymous",
        "type": "httpTrigger",
        "direction": "in",
        "name": "request",
        "methods": [
        "get",
        "post"
        ]
    },
    {
        "type": "http",
        "direction": "out",
        "name": "res"
    },
    {
        "type": "signalR",
        "name": "signalRMessages",
        "connectionStringSetting": "Endpoint=https://xxxx.service.signalr.net;AccessKey=XXXXXXx;Version=1.0;",
        "hubName": "XXXXX",
        "direction": "out"
    }
    ]
}

Then in my second function which will send messages to SignalR service:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    const name = (req.query.name || (req.body && req.body.name));
    const responseMessage = name
        ? "Hello, " + name + ". This HTTP triggered function executed successfully."
        : "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

    const updates = [{
        target: 'updated',
        arguments: [responseMessage]
    }];
    context.bindings.signalRMessages = updates;
    context.done();


}

in function.json

{
    "bindings": [
    {
        "authLevel": "anonymous",
        "type": "httpTrigger",
        "direction": "in",
        "name": "req",
        "methods": [
        "get",
        "post"
        ]
    },
    {
        "type": "http",
        "direction": "out",
        "name": "res"
    },
    {
        "type": "signalRConnectionInfo",
        "name": "connectionInfo",
        "hubName": "xxxxxx", <== here I putted the SignalR service name without the domaine
        "direction": "in",
        "connectionStringSetting": "Endpoint=https://XXXXX.service.signalr.net;AccessKey=XXXXXX;Version=1.0;"
    }
    ]
}

Then I local.setting.json

{
    "IsEncrypted": false,
    "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureSignalRConnectionString": "Endpoint=https://xxxxxx.service.signalr.net;AccessKey=xxxxxxxxx;Version=1.0;"
    },
    "Host": {
    "LocalHttpPort": 7072,
    "CORS": "*"
    }
}

I have also set service mode to serverless in SignalR Service setting.

Now I'm trying to test that by running the sendmessages function in the browser which should trigger the signalR function

But when I run the sendMessages function on browser the SignalR Serice function is not triggered and context.bindings contains only req( no res and sendMessages listed in function.json)

Am I missing something in my configuration ?

0

There are 0 best solutions below