Azure / azure-functions-signalrservice-extension

Azure Functions bindings for SignalR Service. Project moved to https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/signalr/Microsoft.Azure.WebJobs.Extensions.SignalRService .
MIT License
97 stars 47 forks source link

SignalR triggers and outputs do not work when using a non-default settingname for 'ConnectionStringSetting' #207

Closed fgheysels closed 3 years ago

fgheysels commented 3 years ago

I've created an Azure Function which has bindings to a serverless Azure SignalR resource. In the Azure SignalR resource, I've configured 'Upstream' to my Azure Function.

The Azure Function App contains multiple functions which have SignalR triggers or SignalR outputs, like this:

[FunctionName(nameof(SubscribeToDeviceAsync))]
public static async Task SubscribeToDeviceAsync(
    [SignalRTrigger("telemetry", "messages", nameof(SubscribeToDeviceAsync),
                    parameterNames: new string[]{ "deviceId"}, 
                    ConnectionStringSetting = "DeviceTelemetrySignalRConnectionString")] InvocationContext invocationContext,
    string deviceId,
    ILogger logger) {}

or

[FunctionName(nameof(TelemetryNotifier))]
public static async Task Run(
        [EventHubTrigger("%TelemetryEventHub_Name%", Connection = "TelemetryEventHub_ConnectionString", ConsumerGroup = "%TelemetryNotifier_ConsumerGroup%")]
        EventData[] events,
        [SignalR(ConnectionStringSetting = "DeviceTelemetrySignalRConnectionString", HubName = "telemetry")]
        IAsyncCollector<SignalRMessage> signalRMessages,
        ILogger log)

Note that I've specified a custom setting-name for the SignalR connectionstring setting (as is documented here ) When I run my Function, I get InvalidOperationExceptions which say:

Exception while executing function: TelemetryNotifier The SignalR Service connection string or endpoints are not set.

When I remove the ConnectionStringSetting from my bindings, and configure the function to have a setting named AzureSignalRConnectionString, then everything works.

fgheysels commented 3 years ago

It looks like the custom setting name on the output binding on IAsyncCollector works with the custom settingname.

When I call the SubscribeToDeviceAsync method however, which has the SignalRTrigger binding, I get the response:

Microsoft.AspNetCore.SignalR.HubException: 'The SignalR Service connection string or endpoints are not set.'

As soon as I change the SignalRTrigger binding (remove the ConnectionStringSetting property-name and add a setting AzureSignalRConnectionString to my Function configuration, the function works as expected.

Y-Sindo commented 3 years ago

ConnectionStringSetting for SignalRTrigger should work in traditional mode, like the sample you give. I am unable to reproduce the problem. Could you give a reproducible function project?

fgheysels commented 3 years ago

@Y-Sindo , I've created a sample project which can be found here.

Y-Sindo commented 3 years ago

Already reproduced the problem. invocationContext.GetGroupsAsync() method doesn't respect the ConnectionStringSetting. Will fix later.