SignalR 服务的 Azure 事件网格事件架构Azure Event Grid event schema for SignalR Service

本文提供了 SignalR 服务事件的属性和架构。This article provides the properties and schema for SignalR Service events.  有关事件架构的简介,请参阅 Azure 事件网格事件架构For an introduction to event schemas, see Azure Event Grid event schema. 它还提供了一个快速入门和教程的列表,这些快速入门和教程介绍如何使用 Azure SignalR 作为事件源。It also gives you a list of quick starts and tutorials to use Azure SignalR as an event source.

可用事件类型Available event types

SignalR 服务发出以下事件类型:SignalR Service emits the following event types:

事件类型Event type 说明Description
Microsoft.SignalRService.ClientConnectionConnectedMicrosoft.SignalRService.ClientConnectionConnected 当连接客户端连接时引发。Raised when a client connection connected.
Microsoft.SignalRService.ClientConnectionDisconnectedMicrosoft.SignalRService.ClientConnectionDisconnected 当客户端连接断开连接时引发。Raised when a client connection disconnected.

示例事件Example event

以下示例显示了客户端连接已连接事件的架构:The following example shows the schema of a client connection connected event:

[{
  "topic": "/subscriptions/{subscription-id}/resourceGroups/signalr-rg/providers/Microsoft.SignalRService/SignalR/signalr-resource",
  "subject": "/hub/chat",
  "eventType": "Microsoft.SignalRService.ClientConnectionConnected",
  "eventTime": "2019-06-10T18:41:00.9584103Z",
  "id": "831e1650-001e-001b-66ab-eeb76e069631",
  "data": {
    "timestamp": "2019-06-10T18:41:00.9584103Z",
    "hubName": "chat",
    "connectionId": "crH0uxVSvP61p5wkFY1x1A",
    "userId": "user-eymwyo23"
  },
  "dataVersion": "1.0",
  "metadataVersion": "1"
}]

客户端连接断开连接事件的架构类似于:The schema for a client connection disconnected event is similar:

[{
  "topic": "/subscriptions/{subscription-id}/resourceGroups/signalr-rg/providers/Microsoft.SignalRService/SignalR/signalr-resource",
  "subject": "/hub/chat",
  "eventType": "Microsoft.SignalRService.ClientConnectionDisconnected",
  "eventTime": "2019-06-10T18:41:00.9584103Z",
  "id": "831e1650-001e-001b-66ab-eeb76e069631",
  "data": {
    "timestamp": "2019-06-10T18:41:00.9584103Z",
    "hubName": "chat",
    "connectionId": "crH0uxVSvP61p5wkFY1x1A",
    "userId": "user-eymwyo23",
    "errorMessage": "Internal server error."
  },
  "dataVersion": "1.0",
  "metadataVersion": "1"
}]

事件属性Event properties

事件具有以下顶级数据:An event has the following top-level data:

属性Property 类型Type 说明Description
topic stringstring 事件源的完整资源路径。Full resource path to the event source. 此字段不可写入。This field isn't writeable. 事件网格提供此值。Event Grid provides this value.
subject stringstring 事件主题的发布者定义路径。Publisher-defined path to the event subject.
eventType stringstring 此事件源的一个注册事件类型。One of the registered event types for this event source.
eventTime stringstring 基于提供程序 UTC 时间的事件生成时间。The time the event is generated based on the provider's UTC time.
id 字符串string 事件的唯一标识符。Unique identifier for the event.
data objectobject SignalR 服务事件数据。SignalR Service event data.
dataVersion stringstring 数据对象的架构版本。The schema version of the data object. 发布者定义架构版本。The publisher defines the schema version.
metadataVersion stringstring 事件元数据的架构版本。The schema version of the event metadata. 事件网格定义顶级属性的架构。Event Grid defines the schema of the top-level properties. 事件网格提供此值。Event Grid provides this value.

数据对象具有以下属性:The data object has the following properties:

属性Property 类型Type 说明Description
timestamp stringstring 基于提供程序 UTC 时间的事件生成时间。The time the event is generated based on the provider's UTC time.
hubName 字符串string 客户端连接所属的中心。The hub that the client connection belongs to.
connectionId stringstring 客户端连接的唯一标识符。The unique identifier for the client connection.
userId stringstring 声明中定义的用户标识符。The user identifier defined in claim.
errorMessage stringstring 导致连接断开连接的错误。The error that causes the connection disconnected.

教程和操作指南Tutorials and how-tos

标题Title 说明Description
使用事件网格响应 Azure SignalR 服务事件React to Azure SignalR Service events by using Event Grid 概述 Azure SignalR 服务与事件网格的集成。Overview of integrating Azure SignalR Service with Event Grid.
如何将 Azure SignalR 服务事件发送到事件网格How to send Azure SignalR Service events to Event Grid 演示如何通过事件网格将 Azure SignalR 服务事件发送到应用程序。Shows how to send Azure SignalR Service events to an application through Event Grid.

后续步骤Next steps