Перейти к файлу
Liangying.Wei 3e87c3ce27
Simplify the workflow (#289)
* Simplify the workflow

* clean
2022-11-28 13:18:52 +08:00
.github/workflows Add .netcore 2.1,3.1 to GitHub CI 2021-04-08 14:13:03 +08:00
binding-library/java Add connection id related apis (#68) 2019-07-22 15:18:54 +08:00
build Update SDK to 1.11 (#272) 2021-09-09 13:55:19 +08:00
docs Add doc on customizing routing for js (#220) 2021-05-11 18:23:41 +08:00
images Upgrade korebuild to net5.0 (#170) 2021-02-26 10:12:23 +08:00
samples Simplify the workflow (#289) 2022-11-28 13:18:52 +08:00
src Fix `AzureComponentFactory` is null (#274) 2021-09-13 14:53:30 +08:00
test Fix broken tests after SDK behaviour changes 2021-09-03 16:31:47 +08:00
.gitignore Add E2E test for send, group management (#178) 2021-03-17 13:14:33 +08:00
Directory.Build.props Upgrade korebuild to net5.0 (#170) 2021-02-26 10:12:23 +08:00
Directory.Build.targets Update build to use KoreBuild (#24) 2018-09-14 16:16:00 +08:00
LICENSE Change to Microsoft MIT license 2018-07-25 00:34:23 -07:00
README.md Update README.md (#284) 2021-12-09 14:17:38 +08:00
SECURITY.md Microsoft mandatory file (#287) 2022-07-29 11:34:22 +08:00
azure-functions-signalrservice-extension.sln Remove e2e function projects from main solution (#185) 2021-03-18 14:34:23 +08:00
build.cmd Update build to use KoreBuild (#24) 2018-09-14 16:16:00 +08:00
build.sh make build.sh executable 2018-09-19 15:30:21 +08:00
korebuild-lock.txt Upgrade korebuild to net5.0 (#170) 2021-02-26 10:12:23 +08:00
run.cmd Update build to use KoreBuild (#24) 2018-09-14 16:16:00 +08:00
run.ps1 Update .Net SDK version to 5.0.301 in korebuild (#249) 2021-06-24 12:54:43 +08:00
run.sh Update .Net SDK version to 5.0.301 in korebuild (#249) 2021-06-24 12:54:43 +08:00
version.props Update SDK to 1.11 (#272) 2021-09-09 13:55:19 +08:00

README.md

Azure Functions Bindings for Azure SignalR Service

Project moved to azure-sdk-for-net repo.

Build Status

Travis: travis

NuGet Packages

Package Name Target Framework NuGet
Microsoft.Azure.WebJobs.Extensions.SignalRService .NET Core App 2.1
.NET Core App 3.1
NuGet

Intro

These bindings allow Azure Functions to integrate with Azure SignalR Service.

Supported scenarios

  • Allow clients to serverlessly connect to a SignalR Service hub without requiring an ASP.NET Core backend
  • Use Azure Functions (any language supported by V2) to broadcast messages to all clients connected to a SignalR Service hub.
  • Use Azure Functions (any language supported by V2) to send messages to a single user, or all the users in a group.
  • Use Azure Functions (any language supported by V2) to manage group users like add/remove a single user in a group.
  • Example scenarios include: broadcast messages to a SignalR Service hub on HTTP requests and events from Cosmos DB change feed, Event Hub, Event Grid, etc
  • Use multiple Azure SignalR Service instances for resiliency and disaster recovery in Azure Functions. See details in Multiple SignalR service endpoint support.

Bindings

SignalRConnectionInfo input binding makes it easy to generate the token required for clients to initiate a connection to Azure SignalR Service.

SignalR output binding allows messages to be broadcast to an Azure SignalR Service hub.

Prerequisites

Usage

Create Azure SignalR Service instance

  1. Create Azure SignalR Service instances in the Azure Portal. Note the connection strings, you'll need them later.

Create Function App with extension

  1. In a new folder, create a new Azure Functions app.
    • func init
  2. Install this Functions extension.
    • func extensions install -p Microsoft.Azure.WebJobs.Extensions.SignalRService -v 1.0.0

Add application setting for SignalR connection string

  1. Create an app setting called AzureSignalRConnectionString with the SignalR connection string.
    • On localhost, use local.settings.json
    • In Azure, use App Settings

Using the SignalRConnectionInfo input binding

In order for a client to connect to SignalR, it needs to obtain the SignalR Service client hub URL and an access token.

  1. Create a new function named negotiate and use the SignalRConnectionInfo input binding to obtain the connection information and return it. Take a look at this sample.
  2. Client connects to the negotiate function as it's a normal SignalR hub. See this file for a sample usage.

Binding schema:

{
  "type": "signalRConnectionInfo",
  "name": "connectionInfo",
  "hubName": "<hub_name>",
  "connectionStringSetting": "<setting_name>", // Defaults to AzureSignalRConnectionString
  "direction": "in"
}

Using the SignalR output binding

The SignalR output binding can be used to broadcast messages to all clients connected a hub. Take a look at this sample:

Binding schema:

{
  "type": "signalR",
  "name": "signalRMessages", // name of the output binding
  "hubName": "<hub_name>",
  "connectionStringSetting": "<setting_name>", // Defaults to AzureSignalRConnectionString
  "direction": "out"
}

To send one or more messages, set the output binding to an array of objects:

module.exports = function (context, req) {
  context.bindings.signalRMessages = [{
    "target": "newMessage", // name of the client method to invoke
    "arguments": [
      req.body // arguments to pass to client method
    ]
  }];
  context.done();
};

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.