Real-time apps with Azure SignalR Service and Azure Functions
Azure SignalR Services combined with Azure Functions allows you to run real-time messaging web apps in a serverless environment. This article provides an overview of how the services work together.
Azure SignalR Service and Azure Functions are both fully managed, highly scalable services. They enable you to focus on building applications instead of managing infrastructure. It's common to use the two services together to provide real-time communications in a serverless environment.
Integrate real-time communications with Azure services
The Azure Functions service allows you to write code in several languages, including JavaScript, Python, C#, and Java that triggers whenever events occur in the cloud. Examples of these events include:
- HTTP and webhook requests
- Periodic timers
- Events from Azure services, such as:
- Event Grid
- Event Hubs
- Service Bus
- Azure Cosmos DB change feed
- Storage blobs and queues
- Logic Apps connectors such as Salesforce and SQL Server
By using Azure Functions to integrate these events with Azure SignalR Service, you have the ability to notify thousands of clients whenever events occur.
Some common scenarios for real-time serverless messaging that you can implement with Azure Functions and SignalR Service include:
- Visualize IoT device telemetry on a real-time dashboard or map.
- Update data in an application when documents update in Azure Cosmos DB.
- Send in-app notifications when new orders are created in Salesforce.
SignalR Service bindings for Azure Functions
The SignalR Service bindings for Azure Functions allow an Azure Function app to publish messages to clients connected to SignalR Service. Clients can connect to the service using a SignalR client SDK that is available in .NET, JavaScript, and Java, with more languages coming soon.
An example scenario
Using Azure Functions to integrate with Azure Cosmos DB is an example of utilizing the SignalR Service bindings to send real-time messages when new events appear on an Azure Cosmos DB change feed.
- A change is made in an Azure Cosmos DB collection.
- The change event is propagated to the Azure Cosmos DB change feed.
- The Azure Cosmos DB trigger activates an Azure Function in response to the change event.
- The SignalR Service output binding publishes a message to SignalR Service.
- The SignalR Service publishes the message to all connected clients.
Authentication and users
SignalR Service allows you to broadcast messages to all or a subset of clients, such as those belonging to a single user. You can combine the SignalR Service bindings for Azure Functions with App Service authentication to authenticate users with providers such as Microsoft Entra ID. You can then send messages directly to these authenticated users.
Next steps
For full details on how to use Azure Functions and SignalR Service together visit the following resources:
- Azure Functions development and configuration with SignalR Service
- Enable automatic updates in a web application using Azure Functions and SignalR Service
To try out the SignalR Service bindings for Azure Functions, see: