Broadcast Real-time Updates from Cosmos DB with SignalR Service and Azure Functions
Monday, September 24, 2018
Azure Cosmos DB has a nifty change feed feature that tracks create and update events on documents in a collection. Applications, including serverless apps built with Azure Functions, can read events from the change feed and listen to new events on the change feed in real-time.
Azure SignalR Service is a managed service that allows applications to broadcast real-time messages to many connected clients over WebSockets and other supported transports.
September 24, 2018 - Azure SignalR Service is now generally available!
March 6, 2019 - SignalR Service bindings for Azure Functions are now generally available!
In this article, we'll look at how we can use Azure Functions and SignalR Service to broadcast real-time document changes in Cosmos DB to clients over WebSockets.
Overview
Here's how all the pieces fit together.
- A document is created or updated in Cosmos DB.
- The change or update event is automatically logged in the Cosmos DB change feed.
- Using the Cosmos DB trigger, an Azure Function is invoked when the event appears in the change feed.
- Using the SignalR Service output binding, the function outputs a message to SignalR Service.
- SignalR Service sends the message to all connected clients over WebSockets.
![](/post-assets/2018-09-24/architecture-overview.png)
The SignalR client SDK is available in JavaScript and .NET Standard. There's also a Java client coming soon. We'll use a simple Vue.js app in a browser for this project. Using the .NET Standard SDK, we can also build desktop apps with .NET Framework and .NET Core or mobile apps with Xamarin to receive messages from SignalR Service.
Azure Cosmos DB has a nifty change feed feature that tracks create and update events on documents in a collection. Applications, including serverless apps built with Azure Functions, can read events from the change feed and listen to new events on the change feed in real-time.
Azure SignalR Service is a managed service that allows applications to broadcast real-time messages to many connected clients over WebSockets and other supported transports.
September 24, 2018 - Azure SignalR Service is now generally available!
March 6, 2019 - SignalR Service bindings for Azure Functions are now generally available!
In this article, we'll look at how we can use Azure Functions and SignalR Service to broadcast real-time document changes in Cosmos DB to clients over WebSockets.
Overview
Here's how all the pieces fit together.
- A document is created or updated in Cosmos DB.
- The change or update event is automatically logged in the Cosmos DB change feed.
- Using the Cosmos DB trigger, an Azure Function is invoked when the event appears in the change feed.
- Using the SignalR Service output binding, the function outputs a message to SignalR Service.
- SignalR Service sends the message to all connected clients over WebSockets.
The SignalR client SDK is available in JavaScript and .NET Standard. There's also a Java client coming soon. We'll use a simple Vue.js app in a browser for this project. Using the .NET Standard SDK, we can also build desktop apps with .NET Framework and .NET Core or mobile apps with Xamarin to receive messages from SignalR Service.