Overview
This sample demonstrates how to push real-time notifications to C# clients using Azure SignalR Service combined with Azure Functions and PlayFab’s Rules and Matchmaking systems. When a player logs in, a PlayFab Rule fires an Azure Function that broadcasts the login event to connected clients via SignalR. When two players enter a matchmaking queue and a match is found, a second Rule triggers a queue-based Azure Function that notifies both players through SignalR. Once matched, the players can exchange chat messages in real time.What the sample demonstrates
- Push notifications from PlayFab events to clients without polling
- PlayFab Rules triggering Azure Functions on
player_logged_inandmatch_foundevents - Azure Queue Functions as an event bridge between PlayFab and SignalR
- A console C# client that connects to SignalR and participates in matchmaking and chat
Prerequisites
- Visual Studio 2019 with Azure development workload enabled
- An Azure subscription
- A PlayFab account with a title created for testing
Architecture
| Component | Role |
|---|---|
| PlayFab | Authentication, Rules engine, Matchmaking queue |
| Azure Functions | HTTP + Queue triggered functions; bridge between PlayFab and SignalR |
| Azure SignalR Service | Manages WebSocket connections; delivers push messages to clients |
| Azure Storage Queue | Carries match_found payloads from PlayFab to the MatchFound function |
| MessagingClient | Console app that logs in, connects to SignalR, and joins matchmaking |
Azure setup
Create a SignalR Service instance
Follow the Azure SignalR Service quickstart to provision a new SignalR Service instance in the Azure Portal.
Create a Function App
Create a new Function App as described in the Azure Functions quickstart.
The Function App provisioning wizard requires you to create or select a Storage Account. Take note of this storage account — you will need its connection string in a later step.
Configuration
Set the SignalR connection string
- In the Azure Portal, open your SignalR Service instance.
- Navigate to Settings → Keys.
- Copy the full CONNECTION STRING value.
- Open
local.settings.jsonin thePlayFab.SignalRSampleproject. - Replace the placeholder value for
AzureSignalRConnectionStringwith the copied string.
Set the storage connection string
- In the Azure Portal, open the Storage Account associated with your Function App.
- Navigate to Settings → Access Keys.
- Copy the full Connection String value.
- Open
local.settings.jsonin thePlayFab.SignalRSampleproject. - Replace the placeholder value for
AzureWebJobsStoragewith the copied string.
Set the PlayFab Title ID
- Open the PlayFab Game Manager and select your title.
- Copy the 4–5 hex digit Title ID.
- Open
Program.csin theMessagingClientproject. - Find the constant declaration and replace
XXXXXwith your Title ID:
Program.cs
Azure configuration
The connection strings you set locally must also be present in the Azure Portal so that the deployed Function App can use them.Copy settings to Application Settings
- In the Azure Portal, open your Function App.
- Click Configuration under the Settings section.
- Under Application settings, click New application setting.
- Add
AzureSignalRConnectionStringwith the same value you set locally. - Repeat for
AzureWebJobsStorage. - Click Save.
Build and publish
Import the publish profile
- In the Azure Portal, open your Function App and click Get publish profile. Save the
.PublishSettingsfile locally. - In Visual Studio, right-click the
PlayFab.SignalRSampleproject and choose Publish…. - Click Start, then Import Profile… in the bottom left.
- Select the
.PublishSettingsfile you downloaded.
PlayFab configuration
Get Azure Function URLs
Before configuring PlayFab, collect the invokable URLs for the HTTP-triggered functions:- Open the Azure Portal and navigate to your Function App.
- For each HTTP function (
GetSignalRConnection,PlayerLogin,SendChatMessage), click Get Function URL and copy it.
MatchFound does not have an HTTP URL — it is triggered by the Azure Storage Queue, not by HTTP.Register functions and configure rules
Register HTTP Azure Functions
In PlayFab Game Manager, go to Automation → Cloud Script → Functions and register three HTTP functions:
For each: click Register Function, select HTTP as the trigger type, enter the name, paste the URL, and save.
| Function name | Trigger type | URL |
|---|---|---|
GetSignalRConnection | HTTP | Copied URL |
PlayerLogin | HTTP | Copied URL |
SendChatMessage | HTTP | Copied URL |
Register the MatchFound queue function
Register the queue-triggered function:
- Click Register Function.
- Select Queue as the trigger type.
- Enter
MatchFoundas the function name. - Enter
matchfoundas the queue name. - Paste the Storage Account connection string.
- Save the function.
Create Rules
Go to Automation → Rules and create two rules:Rule 1 — Broadcast Friend Login
Rule 2 — Matchmaking Notifications
| Field | Value |
|---|---|
| Name | Broadcast Friend Login |
| Event type | com.playfab.player_logged_in |
| Action type | Execute Azure Function |
| Function | PlayerLogin |
| Field | Value |
|---|---|
| Name | Matchmaking Notifications |
| Event type | playfab.matchmaking.match_found |
| Action type | Execute Azure Function |
| Function | MatchFound |
Running the sample
Build theMessagingClient project and launch two or more instances of the executable (find the local .exe after building). Each instance will:
- Log in to PlayFab using a unique ID derived from the local machine name.
- Establish a SignalR WebSocket connection by calling
GetSignalRConnection. - Join the
nr_simplematchmaking queue. - Receive a real-time notification via SignalR when a match is found.
- Enter a chat channel with the matched player.
- Send and receive chat messages via
SendChatMessage.
Broadcast Friend Login rule.
To exit the chat session, send an empty line (press Enter without typing a message).
Important notes
If more than two instances are running simultaneously, PlayFab may form multiple separate 2-player matches rather than one group match. Each pair of matched players gets its own isolated chat channel.
Tic Tac Toe Azure Functions
Another C# Azure Functions sample — game logic for the Tic Tac Toe Unity game.
Samples overview
Browse all PlayFab samples.
