0

I'm using Azure SignalR in serverless mode. I've an Azure Function which receives events from Event Hub and sends messages to Azure SignalR.

[Function(nameof(EventHubEventsHandler))]
[SignalROutput(HubName = "userevents", ConnectionStringSetting = "SignalRConnectionSetting")]
public async Task<List<SignalRMessageAction>> Run([EventHubTrigger("userschanged", Connection = "EventHubConnectionSetting")] EventData[] events)

{
    var messages = new List<SignalRMessageAction>();
    foreach (EventData @event in events)
    {
        try
        {
           messages.Add(new SignalRMessageAction("userChanged")
           {
               Arguments = new[] { "user changed" },
           });
        }
        catch (Exception ex)
        {
            ...
        }
    }
    return messages;
}

The connection string SignalRConnectionSetting in Azure Function App settings is defined like Endpoint=https://xxx.service.signalr.net;AccessKey=yyy;Version=1.0;

Azure Function is triggered successfully, but in Application Insights I see that the attempt to send message to Azure SignalR fails with 403 forbidden.

What I see in the logs:

GET https://xxx.service.signalr.net/api/v1/auth/accessKey
Result code: 200
POST https://xxx.service.signalr.net/api/hubs/userevents/:send?api-version=2022-06-01
Result code: 403
System.Net.Http.HttpRequestException
Exception while executing function: Functions.EventHubEventsHandler Azure SignalR service runtime error. Request Uri: https://xxx.service.signalr.net/api/hubs/userevents/:send?api-version=2022-06-01 Response status code does not indicate success: 403 (Forbidden) 

I've no clue what can be wrong.

7
  • Are you able to execute the function locally as my function works perfectly post deploying too? Commented May 22, 2024 at 10:01
  • While executing it locally, use live trace tool in SignalR to see the incoming messages Commented May 22, 2024 at 10:04
  • After deploying the function code, are you able to see this Commented May 22, 2024 at 13:57
  • @IkhtesamAfrin I see the key signalr_extension. I've tried live trace tool, but even if it is enabled, it shows me 'Not Ready' and I don't see any incoming messages. Commented May 22, 2024 at 14:11
  • enable it and then click on save like this, once it is done it will be ready to show you the logs Commented May 22, 2024 at 14:25

1 Answer 1

1
  • Refresh the Signal R and Event Hub Connection strings and update the new values in the Application settings.
  • Make sure you have enabled Public Access in all the services.

Follow below steps to achieve your requirement.

  • Created a EventHub Trigger Azure function to receive events from EventHub and send the messages to signal R.

Code Snippet:

[Function(nameof(EventHubEventsHandler))]
[SignalROutput(HubName = "userevents", ConnectionStringSetting = "SignalRConnectionSetting")]
public async Task<List<SignalRMessageAction>> Run([EventHubTrigger("kpeventhub", Connection = "EventHubConnectionString")] EventData[] events)
{
    var messages = new List<SignalRMessageAction>();
    foreach (EventData @event in events)
    {
        try
        {
            messages.Add(new SignalRMessageAction("userChanged")
            {
                Arguments = new[] { "user changed" },
            });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "An error occurred while processing the event data.");
        }
    }
    return messages;
}
  • Created a Signal R service and configured with Event Hub.
  • Enabled Application Insights in the Azure function app.
  • Added below Application Settings in the Function App=>Environment Variables:
"EventHubConnectionString": "Endpoint=sb://<eventhubnamespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=y8TjnnTJA2XXXXXX7+AEhJudoTs=",
"SignalRConnectionSetting": "Endpoint=https://<signalr>.service.signalr.net;AccessKey=0vSNRXjzPnyQTQXXXXXnNZtC5pp8=;Version=1.0;"
  • Enable Live Trace in Signal R service=>Monitoring:

enter image description here

  • Sending the Events:

enter image description here

Function App Invocations:

enter image description here

Live Trace:

enter image description here

  • Logs in Application Insights:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.