您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure Functions 的 SignalR Service 绑定SignalR Service bindings for Azure Functions

本文介绍如何使用 Azure Functions 中的 SignalR 服务绑定进行身份验证,并向连接到 Azure SignalR 服务的客户端发送实时消息。This article explains how to authenticate and send real-time messages to clients connected to Azure SignalR Service by using SignalR Service bindings in Azure Functions. Azure Functions 支持 SignalR 服务的输入和输出绑定。Azure Functions supports input and output bindings for SignalR Service.

此参考信息面向 Azure Functions 开发人员。This is reference information for Azure Functions developers. Azure Functions 的新手请从以下资源入手:If you're new to Azure Functions, start with the following resources:

包 - Functions 2.xPackages - Functions 2.x

中提供 SignalR 服务绑定Microsoft.Azure.WebJobs.Extensions.SignalRService NuGet 包,版本 1.*。The SignalR Service bindings are provided in the Microsoft.Azure.WebJobs.Extensions.SignalRService NuGet package, version 1.*. azure-functions-signalrservice-extension GitHub 存储库中提供了此包的源代码。Source code for the package is in the azure-functions-signalrservice-extension GitHub repository.

下表说明了如何在每个开发环境中添加对此绑定的支持。The following table tells how to add support for this binding in each development environment.

开发环境Development environment 添加支持To add support in
Functions 2.xFunctions 2.x
本地开发 - C# 类库Local development - C# class library 安装包Install the package
本地开发 - C# 脚本、JavaScript、F#Local development - C# script, JavaScript, F# 注册扩展Register the extension
门户开发Portal development 注册扩展Register the extension

若要了解如何更新门户中的现有绑定扩展而不必重新发布函数应用项目,请参阅更新扩展To learn how to update existing binding extensions in the portal without having to republish your function app project, see Update your extensions.

Java 注释Java annotations

若要在 Java 函数中使用 SignalR 服务批注,您需要添加依赖项azure-函数-java-库-signalr到 pom.xml 项目 (版本 1.0 或更高版本)。To use the SignalR Service annotations in Java functions, you need to add a dependency to the azure-functions-java-library-signalr artifact (version 1.0 or higher) to your pom.xml.

<dependency>
    <groupId>com.microsoft.azure.functions</groupId>
    <artifactId>azure-functions-java-library-signalr</artifactId>
    <version>1.0.0</version>
</dependency>

备注

若要在 Java 中使用 SignalR 服务绑定,请确保使用的是 Azure Functions Core Tools(主机版本 2.0.12332)2.4.419 版或更高版本。To use the SignalR Service bindings in Java, make sure you are using version 2.4.419 or higher of the Azure Functions Core Tools (host version 2.0.12332).

使用 Azure Functions 和 SignalR 服务Using SignalR Service with Azure Functions

有关如何配置和将 SignalR 服务和 Azure Functions 一起使用的详细信息,请参阅Azure Functions 开发和使用 Azure SignalR 服务配置For details on how to configure and use SignalR Service and Azure Functions together, refer to Azure Functions development and configuration with Azure SignalR Service.

SignalR 连接信息输入绑定SignalR connection info input binding

客户端在连接到 Azure SignalR 服务之前,必须检索服务终结点 URL 和有效的访问令牌。Before a client can connect to Azure SignalR Service, it must retrieve the service endpoint URL and a valid access token. SignalRConnectionInfo 输入绑定生成 SignalR 服务终结点 URL 和有效的令牌,这两者可以用来连接到服务。The SignalRConnectionInfo input binding produces the SignalR Service endpoint URL and a valid token that are used to connect to the service. 由于此令牌有时间限制,并且可以用来对需要连接的特定用户进行身份验证,因此不应缓存此令牌,也不应在客户端之间共享它。Because the token is time-limited and can be used to authenticate a specific user to a connection, you should not cache the token or share it between clients. 使用此绑定的 HTTP 触发器可供客户端用来检索连接信息。An HTTP trigger using this binding can be used by clients to retrieve the connection information.

参阅语言特定的示例:See the language-specific example:

有关如何使用此绑定创建一个可供 SignalR 客户端 SDK 的"协商"函数的详细信息,请参阅Azure Functions 开发和配置项目SignalR 服务概念文档。For more information on how this binding is used to create a "negotiate" function that can be consumed by a SignalR client SDK, see the Azure Functions development and configuration article in the SignalR Service concepts documentation.

2.xC#输入示例2.x C# input examples

以下示例演示了一个 C# 函数,该函数使用输入绑定获取 SignalR 连接信息,并通过 HTTP 将其返回。The following example shows a C# function that acquires SignalR connection information using the input binding and returns it over HTTP.

[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
    [HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req,
    [SignalRConnectionInfo(HubName = "chat")]SignalRConnectionInfo connectionInfo)
{
    return connectionInfo;
}

已进行身份验证的令牌Authenticated tokens

如果此函数由经过身份验证的客户端触发,则可向生成的令牌添加用户 ID 声明。If the function is triggered by an authenticated client, you can add a user ID claim to the generated token. 您可以轻松地将身份验证添加到函数应用使用应用服务身份验证You can easily add authentication to a function app using App Service Authentication.

应用服务身份验证会设置名为 x-ms-client-principal-idx-ms-client-principal-name(分别包含经身份验证的用户的客户端主体 ID 和名称)的 HTTP 标头。App Service Authentication sets HTTP headers named x-ms-client-principal-id and x-ms-client-principal-name that contain the authenticated user's client principal ID and name, respectively. 可以使用绑定表达式 {headers.x-ms-client-principal-id}{headers.x-ms-client-principal-name} 将绑定的 UserId 属性设置为任一标头中的值。You can set the UserId property of the binding to the value from either header using a binding expression: {headers.x-ms-client-principal-id} or {headers.x-ms-client-principal-name}.

[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
    [HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req, 
    [SignalRConnectionInfo
        (HubName = "chat", UserId = "{headers.x-ms-client-principal-id}")]
        SignalRConnectionInfo connectionInfo)
{
    // connectionInfo contains an access key token with a name identifier claim set to the authenticated user
    return connectionInfo;
}

2.x JavaScript 输入的示例2.x JavaScript input examples

以下示例演示 function.json 文件中的一个 SignalR 连接信息输入绑定,以及使用该绑定来返回连接信息的 JavaScript 函数The following example shows a SignalR connection info input binding in a function.json file and a JavaScript function that uses the binding to return the connection information.

下面是 function.json 文件中的绑定数据:Here's binding data in the function.json file:

示例 function.json:Example function.json:

{
    "type": "signalRConnectionInfo",
    "name": "connectionInfo",
    "hubName": "chat",
    "connectionStringSetting": "<name of setting containing SignalR Service connection string>",
    "direction": "in"
}

JavaScript 代码如下所示:Here's the JavaScript code:

module.exports = async function (context, req, connectionInfo) {
    context.res.body = connectionInfo;
};

已进行身份验证的令牌Authenticated tokens

如果此函数由经过身份验证的客户端触发,则可向生成的令牌添加用户 ID 声明。If the function is triggered by an authenticated client, you can add a user ID claim to the generated token. 您可以轻松地将身份验证添加到函数应用使用应用服务身份验证You can easily add authentication to a function app using App Service Authentication.

应用服务身份验证会设置名为 x-ms-client-principal-idx-ms-client-principal-name(分别包含经身份验证的用户的客户端主体 ID 和名称)的 HTTP 标头。App Service Authentication sets HTTP headers named x-ms-client-principal-id and x-ms-client-principal-name that contain the authenticated user's client principal ID and name, respectively. 可以使用绑定表达式 {headers.x-ms-client-principal-id}{headers.x-ms-client-principal-name} 将绑定的 userId 属性设置为任一标头中的值。You can set the userId property of the binding to the value from either header using a binding expression: {headers.x-ms-client-principal-id} or {headers.x-ms-client-principal-name}.

示例 function.json:Example function.json:

{
    "type": "signalRConnectionInfo",
    "name": "connectionInfo",
    "hubName": "chat",
    "userId": "{headers.x-ms-client-principal-id}",
    "connectionStringSetting": "<name of setting containing SignalR Service connection string>",
    "direction": "in"
}

JavaScript 代码如下所示:Here's the JavaScript code:

module.exports = async function (context, req, connectionInfo) {
    // connectionInfo contains an access key token with a name identifier
    // claim set to the authenticated user
    context.res.body = connectionInfo;
};

2.x Java 输入的示例2.x Java input examples

下面的示例演示Java 函数,获取使用输入的绑定的 SignalR 连接信息并将其返回通过 HTTP。The following example shows a Java function that acquires SignalR connection information using the input binding and returns it over HTTP.

@FunctionName("negotiate")
public SignalRConnectionInfo negotiate(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> req,
        @SignalRConnectionInfoInput(
            name = "connectionInfo",
            hubName = "chat") SignalRConnectionInfo connectionInfo) {
    return connectionInfo;
}

已进行身份验证的令牌Authenticated tokens

如果此函数由经过身份验证的客户端触发,则可向生成的令牌添加用户 ID 声明。If the function is triggered by an authenticated client, you can add a user ID claim to the generated token. 您可以轻松地将身份验证添加到函数应用使用应用服务身份验证You can easily add authentication to a function app using App Service Authentication.

应用服务身份验证会设置名为 x-ms-client-principal-idx-ms-client-principal-name(分别包含经身份验证的用户的客户端主体 ID 和名称)的 HTTP 标头。App Service Authentication sets HTTP headers named x-ms-client-principal-id and x-ms-client-principal-name that contain the authenticated user's client principal ID and name, respectively. 可以使用绑定表达式 {headers.x-ms-client-principal-id}{headers.x-ms-client-principal-name} 将绑定的 UserId 属性设置为任一标头中的值。You can set the UserId property of the binding to the value from either header using a binding expression: {headers.x-ms-client-principal-id} or {headers.x-ms-client-principal-name}.

@FunctionName("negotiate")
public SignalRConnectionInfo negotiate(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> req,
        @SignalRConnectionInfoInput(
            name = "connectionInfo",
            hubName = "chat",
            userId = "{headers.x-ms-client-principal-id}") SignalRConnectionInfo connectionInfo) {
    return connectionInfo;
}

SignalR 输出绑定SignalR output binding

使用 Azure SignalR 服务,通过 SignalR 输出绑定发送一条或多条消息。Use the SignalR output binding to send one or more messages using Azure SignalR Service. 可以将消息广播给所有连接的客户端,也可以将消息仅广播给已针对给定用户进行身份验证的已连接客户端。You can broadcast a message to all connected clients, or you can broadcast it only to connected clients that have been authenticated to a given user.

此外可以使用它来管理用户所属的组。You can also use it to manage the groups that a user belongs to.

参阅语言特定的示例:See the language-specific example:

2.xC#发送消息输出示例2.x C# send message output examples

广播到所有客户端Broadcast to all clients

以下示例演示一个 C# 函数,该函数使用输出绑定将一条消息发送给所有连接的客户端。The following example shows a C# function that sends a message using the output binding to all connected clients. Target 是需要在每个客户端上调用的方法的名称。The Target is the name of the method to be invoked on each client. Arguments 属性是一个数组,其中包含要传递给客户端方法的零个或多个对象。The Arguments property is an array of zero or more objects to be passed to the client method.

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            Target = "newMessage", 
            Arguments = new [] { message } 
        });
}

发送给用户Send to a user

可以设置 SignalR 消息的 UserId 属性,以便将消息只发送给已针对某个用户进行身份验证的连接。You can send a message only to connections that have been authenticated to a user by setting the UserId property of the SignalR message.

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            // the message will only be sent to this user ID
            UserId = "userId1",
            Target = "newMessage",
            Arguments = new [] { message }
        });
}

发送到组Send to a group

您可以将一条消息发送到通过设置添加到组的连接仅GroupNameSignalR 消息的属性。You can send a message only to connections that have been added to a group by setting the GroupName property of the SignalR message.

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message,
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage
        {
            // the message will be sent to the group with this name
            GroupName = "myGroup",
            Target = "newMessage",
            Arguments = new [] { message }
        });
}

2.xC#组管理输出示例2.x C# group management output examples

SignalR 服务允许用户添加到组中。SignalR Service allows users to be added to groups. 然后可以将消息发送到的组。Messages can then be sent to a group. 可以使用SignalRGroupAction类的SignalR输出绑定来管理用户的组成员身份。You can use the SignalRGroupAction class with the SignalR output binding to manage a user's group membership.

将用户添加到组Add user to a group

下面的示例将用户添加到组。The following example adds a user to a group.

[FunctionName("addToGroup")]
public static Task AddToGroup(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req,
    string userId,
    [SignalR(HubName = "chat")]
        IAsyncCollector<SignalRGroupAction> signalRGroupActions)
{
    return signalRGroupActions.AddAsync(
        new SignalRGroupAction
        {
            UserId = userId,
            GroupName = "myGroup",
            Action = GroupAction.Add
        });
}

从组中删除用户Remove user from a group

下面的示例从组中删除用户。The following example removes a user from a group.

[FunctionName("removeFromGroup")]
public static Task RemoveFromGroup(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req,
    string userId,
    [SignalR(HubName = "chat")]
        IAsyncCollector<SignalRGroupAction> signalRGroupActions)
{
    return signalRGroupActions.AddAsync(
        new SignalRGroupAction
        {
            UserId = userId,
            GroupName = "myGroup",
            Action = GroupAction.Remove
        });
}

2.x JavaScript 发送消息输出示例2.x JavaScript send message output examples

广播到所有客户端Broadcast to all clients

以下示例演示 function.json 文件中的一个 SignalR 输出绑定以及使用该绑定通过 Azure SignalR 服务发送消息的 JavaScript 函数The following example shows a SignalR output binding in a function.json file and a JavaScript function that uses the binding to send a message with Azure SignalR Service. 将输出绑定设置为一个数组,其中包含一条或多条 SignalR 消息。Set the output binding to an array of one or more SignalR messages. SignalR 消息包含一个 target 属性,用于指定要在每个客户端上调用的方法的名称;以及一个 arguments 属性,该属性是一个数组,其中包含要作为参数传递给客户端方法的对象。A SignalR message consists of a target property that specifies the name of the method to invoke on each client, and an arguments property that is an array of objects to pass to the client method as arguments.

下面是 function.json 文件中的绑定数据:Here's binding data in the function.json file:

示例 function.json:Example function.json:

{
  "type": "signalR",
  "name": "signalRMessages",
  "hubName": "<hub_name>",
  "connectionStringSetting": "<name of setting containing SignalR Service connection string>",
  "direction": "out"
}

JavaScript 代码如下所示:Here's the JavaScript code:

module.exports = async function (context, req) {
    context.bindings.signalRMessages = [{
        "target": "newMessage",
        "arguments": [ req.body ]
    }];
};

发送给用户Send to a user

可以设置 SignalR 消息的 userId 属性,以便将消息只发送给已针对某个用户进行身份验证的连接。You can send a message only to connections that have been authenticated to a user by setting the userId property of the SignalR message.

function.json 保持不变。function.json stays the same. JavaScript 代码如下所示:Here's the JavaScript code:

module.exports = async function (context, req) {
    context.bindings.signalRMessages = [{
        // message will only be sent to this user ID
        "userId": "userId1",
        "target": "newMessage",
        "arguments": [ req.body ]
    }];
};

发送到组Send to a group

您可以将一条消息发送到通过设置添加到组的连接仅groupNameSignalR 消息的属性。You can send a message only to connections that have been added to a group by setting the groupName property of the SignalR message.

function.json 保持不变。function.json stays the same. JavaScript 代码如下所示:Here's the JavaScript code:

module.exports = async function (context, req) {
    context.bindings.signalRMessages = [{
        // message will only be sent to this group
        "groupName": "myGroup",
        "target": "newMessage",
        "arguments": [ req.body ]
    }];
};

2.x JavaScript 组管理输出示例2.x JavaScript group management output examples

SignalR 服务允许用户添加到组中。SignalR Service allows users to be added to groups. 然后可以将消息发送到的组。Messages can then be sent to a group. 可以使用SignalR输出绑定来管理用户的组成员身份。You can use the SignalR output binding to manage a user's group membership.

将用户添加到组Add user to a group

下面的示例将用户添加到组。The following example adds a user to a group.

function.jsonfunction.json

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "signalR",
      "name": "signalRGroupActions",
      "connectionStringSetting": "<name of setting containing SignalR Service connection string>",
      "hubName": "chat",
      "direction": "out"
    }
  ]
}

index.jsindex.js

module.exports = async function (context, req) {
  context.bindings.signalRGroupActions = [{
    "userId": req.query.userId,
    "groupName": "myGroup",
    "action": "add"
  }];
};

从组中删除用户Remove user from a group

下面的示例从组中删除用户。The following example removes a user from a group.

function.jsonfunction.json

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "signalR",
      "name": "signalRGroupActions",
      "connectionStringSetting": "<name of setting containing SignalR Service connection string>",
      "hubName": "chat",
      "direction": "out"
    }
  ]
}

index.jsindex.js

module.exports = async function (context, req) {
  context.bindings.signalRGroupActions = [{
    "userId": req.query.userId,
    "groupName": "myGroup",
    "action": "remove"
  }];
};

2.x Java 发送消息输出示例2.x Java send message output examples

广播到所有客户端Broadcast to all clients

下面的示例演示Java 函数发送使用所有连接的客户端的输出绑定的消息。The following example shows a Java function that sends a message using the output binding to all connected clients. target 是需要在每个客户端上调用的方法的名称。The target is the name of the method to be invoked on each client. arguments 属性是一个数组,其中包含要传递给客户端方法的零个或多个对象。The arguments property is an array of zero or more objects to be passed to the client method.

@FunctionName("sendMessage")
@SignalROutput(name = "$return", hubName = "chat")
public SignalRMessage sendMessage(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Object> req) {

    SignalRMessage message = new SignalRMessage();
    message.target = "newMessage";
    message.arguments.add(req.getBody());
    return message;
}

发送给用户Send to a user

可以设置 SignalR 消息的 userId 属性,以便将消息只发送给已针对某个用户进行身份验证的连接。You can send a message only to connections that have been authenticated to a user by setting the userId property of the SignalR message.

@FunctionName("sendMessage")
@SignalROutput(name = "$return", hubName = "chat")
public SignalRMessage sendMessage(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Object> req) {

    SignalRMessage message = new SignalRMessage();
    message.userId = "userId1";
    message.target = "newMessage";
    message.arguments.add(req.getBody());
    return message;
}

发送到组Send to a group

您可以将一条消息发送到通过设置添加到组的连接仅groupNameSignalR 消息的属性。You can send a message only to connections that have been added to a group by setting the groupName property of the SignalR message.

@FunctionName("sendMessage")
@SignalROutput(name = "$return", hubName = "chat")
public SignalRMessage sendMessage(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Object> req) {

    SignalRMessage message = new SignalRMessage();
    message.groupName = "myGroup";
    message.target = "newMessage";
    message.arguments.add(req.getBody());
    return message;
}

2.x Java 组管理输出示例2.x Java group management output examples

SignalR 服务允许用户添加到组中。SignalR Service allows users to be added to groups. 然后可以将消息发送到的组。Messages can then be sent to a group. 可以使用SignalRGroupAction类的SignalROutput输出绑定来管理用户的组成员身份。You can use the SignalRGroupAction class with the SignalROutput output binding to manage a user's group membership.

将用户添加到组Add user to a group

下面的示例将用户添加到组。The following example adds a user to a group.

@FunctionName("addToGroup")
@SignalROutput(name = "$return", hubName = "chat")
public SignalRGroupAction addToGroup(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Object> req,
        @BindingName("userId") String userId) {

    SignalRGroupAction groupAction = new SignalRGroupAction();
    groupAction.action = "add";
    groupAction.userId = userId;
    groupAction.groupName = "myGroup";
    return action;
}

从组中删除用户Remove user from a group

下面的示例从组中删除用户。The following example removes a user from a group.

@FunctionName("removeFromGroup")
@SignalROutput(name = "$return", hubName = "chat")
public SignalRGroupAction removeFromGroup(
        @HttpTrigger(
            name = "req",
            methods = { HttpMethod.POST },
            authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Object> req,
        @BindingName("userId") String userId) {

    SignalRGroupAction groupAction = new SignalRGroupAction();
    groupAction.action = "remove";
    groupAction.userId = userId;
    groupAction.groupName = "myGroup";
    return action;
}

配置Configuration

SignalRConnectionInfoSignalRConnectionInfo

下表解释了在 function.json 文件和 SignalRConnectionInfo 特性中设置的绑定配置属性。The following table explains the binding configuration properties that you set in the function.json file and the SignalRConnectionInfo attribute.

function.json 属性function.json property Attribute 属性Attribute property 说明Description
typetype 必须设置为 signalRConnectionInfoMust be set to signalRConnectionInfo.
directiondirection 必须设置为 inMust be set to in.
namename 变量名称,在连接信息对象的函数代码中使用。Variable name used in function code for connection info object.
hubNamehubName HubNameHubName 此值必须设置为 SignalR 中心(将为其生成连接信息)的名称。This value must be set to the name of the SignalR hub for which the connection information is generated.
userIduserId UserIdUserId 可选:将要在访问密钥令牌中设置的用户标识符声明的值。Optional: The value of the user identifier claim to be set in the access key token.
connectionStringSettingconnectionStringSetting ConnectionStringSettingConnectionStringSetting 应用设置的名称,该设置包含 SignalR 服务连接字符串(默认为“AzureSignalRConnectionString”)The name of the app setting that contains the SignalR Service connection string (defaults to "AzureSignalRConnectionString")

SignalRSignalR

下表解释了在 function.json 文件和 SignalR 特性中设置的绑定配置属性。The following table explains the binding configuration properties that you set in the function.json file and the SignalR attribute.

function.json 属性function.json property Attribute 属性Attribute property 说明Description
typetype 必须设置为 signalRMust be set to signalR.
directiondirection 必须设置为 outMust be set to out.
namename 变量名称,在连接信息对象的函数代码中使用。Variable name used in function code for connection info object.
hubNamehubName HubNameHubName 此值必须设置为 SignalR 中心(将为其生成连接信息)的名称。This value must be set to the name of the SignalR hub for which the connection information is generated.
connectionStringSettingconnectionStringSetting ConnectionStringSettingConnectionStringSetting 应用设置的名称,该设置包含 SignalR 服务连接字符串(默认为“AzureSignalRConnectionString”)The name of the app setting that contains the SignalR Service connection string (defaults to "AzureSignalRConnectionString")

在本地进行开发时,应用设置将取 local.settings.json 文件的值。When you're developing locally, app settings go into the local.settings.json file.

后续步骤Next steps