SignalR Service¶
Add real-time messaging to clients with Azure SignalR Service bindings in PowerShell.
Negotiate Function¶
Clients first call a negotiate endpoint to obtain connection info. Use the signalRConnectionInfo input binding:
function.json:
{
"bindings": [
{
"name": "Request",
"type": "httpTrigger",
"direction": "in",
"methods": ["post"]
},
{
"name": "Response",
"type": "http",
"direction": "out"
},
{
"name": "ConnectionInfo",
"type": "signalRConnectionInfo",
"direction": "in",
"hubName": "notifications",
"connectionStringSetting": "AzureSignalRConnectionString"
}
]
}
run.ps1:
param($Request, $ConnectionInfo, $TriggerMetadata)
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [System.Net.HttpStatusCode]::OK
Body = ($ConnectionInfo | ConvertTo-Json)
})
Broadcasting Messages¶
Use the signalR output binding to push messages to connected clients:
{
"name": "SignalRMessages",
"type": "signalR",
"direction": "out",
"hubName": "notifications",
"connectionStringSetting": "AzureSignalRConnectionString"
}
Push-OutputBinding -Name SignalRMessages -Value @{
target = "newMessage"
arguments = @( @{ text = "Order shipped"; timestamp = (Get-Date).ToString("o") } )
}
Set userId on the message to target a single user, or groupName to target a group.
Serverless mode
Configure the SignalR Service instance in Serverless mode so it works with Azure Functions rather than a self-hosted hub.