2

I wanted to use a SignalR trigger binding with an Azure Function, so the function is executed everytime a message is sent to the SignalR service (also running in Azure). I have tried all examples from the Microsoft documentation, and so far no success. I don't know what I'm doing wrong, so a bit of help would be appreciated :)

The Function App consists of two parts:

Broadcast function

This function is just sending messages to all clients connected to the SignalR service periodically (i.e. broadcasting), every 5 seconds.

The function broadcast/__init__.py looks like:

import json
import azure.functions as func

def main(myTimer: func.TimerRequest, outMessage: func.Out[str]) -> func.HttpResponse:

    outMessage.set(json.dumps({
        "target": "newMessage",
        "arguments": ["test"]
    }))

Its corresponding broadcast/function.json configuration file is:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "*/5 * * * * *"
    },
    {
      "type": "signalR",
      "name": "outMessage",
      "hubName": "testhub",
      "connectionStringSetting": "AzureSignalRConnectionString",
      "direction": "out"
    }
  ]
}

Trigger function

This function should be executed every time that a message is sent to the SignalR service, as explained in the Azure documentation:

The code for trigger/__init__.py is:

import logging
import json
import azure.functions as func

def main(invocation) -> None:
    invocation_json = json.loads(invocation)
    logging.info("Receive {0} from {1}".format(invocation_json['Arguments'][0],
                                               invocation_json['ConnectionId']))

And the trigger/function.json file looks like:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "signalRTrigger",
      "name": "invocation",
      "hubName": "testhub",
      "connectionStringSetting": "AzureSignalRConnectionString",
      "category": "messages",
      "event": "SendMessage",
      "parameterNames": [
          "message"
      ],
      "direction": "in"
    }
  ]
}

I've already set the AzureSignalRConnectionString under "Configuration" -> "Application settings" in the Azure Function, and I also added the "Upstream URL pattern" on the SignalR service, as explained here.

At this point I have tried pretty much every single example I could find, but no success so far. Connecting a JS client works, and the messages can be received, but the trigger function is never executed. What am I doing wrong? Thanks a lot!

chronoclast
  • 81
  • 1
  • 5

0 Answers0