C
C#2mo ago
Joey

✅ SignalR trigger for Azure Function (isolated) does not trigger.

Trying to set up a SignalR trigger that recieves a message from the client. The negotiate work fine, and the connection gets established. I see the message being sent from the client as well, but my function never triggers. The message that gets sent: {"arguments":["Hello from client"],"invocationId":"0","streamIds":[],"target":"sendMessage","type":1} Azure function:
c#
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace HueCue.API;

public class Api(ILogger<Api> logger)
{
private const string HubName = "ChatRoom";

[Function("negotiate")]
public string Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]
HttpRequestData req,
[SignalRConnectionInfoInput(HubName = HubName, ConnectionStringSetting = "AzureSignalR")]
string connectionInfo)
{
logger.LogInformation($"SignalR Connection data requested: {connectionInfo}");

return connectionInfo;
}

[Function(nameof(SendMessage))]
public void SendMessage(
[SignalRTrigger(HubName,"messages", nameof(SendMessage), ConnectionStringSetting = "AzureSignalR")]
SignalRInvocationContext invocationContext)
{
// Extract the message from the arguments
var content = invocationContext.Arguments?.Length > 0
? invocationContext.Arguments[0]?.ToString()
: "(no content)";

logger.LogInformation($"SignalR Message received: {content}");
}
}
c#
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace HueCue.API;

public class Api(ILogger<Api> logger)
{
private const string HubName = "ChatRoom";

[Function("negotiate")]
public string Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]
HttpRequestData req,
[SignalRConnectionInfoInput(HubName = HubName, ConnectionStringSetting = "AzureSignalR")]
string connectionInfo)
{
logger.LogInformation($"SignalR Connection data requested: {connectionInfo}");

return connectionInfo;
}

[Function(nameof(SendMessage))]
public void SendMessage(
[SignalRTrigger(HubName,"messages", nameof(SendMessage), ConnectionStringSetting = "AzureSignalR")]
SignalRInvocationContext invocationContext)
{
// Extract the message from the arguments
var content = invocationContext.Arguments?.Length > 0
? invocationContext.Arguments[0]?.ToString()
: "(no content)";

logger.LogInformation($"SignalR Message received: {content}");
}
}
24 Replies
Joey
JoeyOP2mo ago
index.html (client):
<html>
<body>
<h1>Azure SignalR Serverless Sample</h1>
<div id="messages"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/3.1.7/signalr.min.js"></script>
<script>
const apiBaseUrl = window.location.origin;
const connection = new signalR.HubConnectionBuilder()
.withUrl(apiBaseUrl + '/api')
.configureLogging(signalR.LogLevel.Information)
.build();

connection.start().then(() => {
console.log("Connection established");
console.log(connection)
connection.invoke("SendMessage", "Hello from client")
}).catch(console.error);
</script>
</body>

</html>
<html>
<body>
<h1>Azure SignalR Serverless Sample</h1>
<div id="messages"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/3.1.7/signalr.min.js"></script>
<script>
const apiBaseUrl = window.location.origin;
const connection = new signalR.HubConnectionBuilder()
.withUrl(apiBaseUrl + '/api')
.configureLogging(signalR.LogLevel.Information)
.build();

connection.start().then(() => {
console.log("Connection established");
console.log(connection)
connection.invoke("SendMessage", "Hello from client")
}).catch(console.error);
</script>
</body>

</html>
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
The "messages" is not the hub name, that's the category I don't have a github project, this is all the code
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
No description
Joey
JoeyOP2mo ago
I don't think that's the issue though, that's just the path where the negotiate endpoint lives It manages to establish the connection with that set-up
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
Think it might be this
No description
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
If I run this function, the connection works just fine
No description
Joey
JoeyOP2mo ago
The stuff about SignalR Service integration Think I need to set up a URL to be able to use the trigger The connection works if I don't use the trigger
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
Of the js sdk?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
Ah I took that straight from one of the examples
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
Makes sense, I'll try it thanks
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Joey
JoeyOP2mo ago
Changed it to <script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/6.0.1/signalr.js"></script> This serverless stuff isn't too straightforward is it 😂
Joey
JoeyOP2mo ago
Stack Overflow
Local development with Azure SignalR Service and Azure Functions
I'm using Azure SignalR Services, which is running in the cloud, and running an Azure Function App, which runs locally on my laptop on localhost. I have the following hub: public class Leaderboard...
Joey
JoeyOP2mo ago
Azure SignalR Local Emulator for serverless development
Learn how to use Azure SignalR Local Emulator for serverless development
Joey
JoeyOP2mo ago
Thanks for taking the time to look at it!
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?