什么是 Azure 通知中心?What is Azure Notification Hubs?

Azure 通知中心提供易于使用且横向扩展的推送引擎,可用于从任何后端(云或本地)向任何平台(iOS、Android、Windows、Kindle、Baidu 等)发送通知。Azure Notification Hubs provide an easy-to-use and scaled-out push engine that enables you to send notifications to any platform (iOS, Android, Windows, Kindle, Baidu, etc.) from any backend (cloud or on-premises). 通知中心非常适合用于企业和消费者方案。Notification Hubs works great for both enterprise and consumer scenarios. 下面是一些示例方案:Here are a few example scenarios:

  • 以较低的延迟向数百万用户发送突发新闻通知。Send breaking news notifications to millions with low latency.
  • 向感兴趣的用户群发送基于位置的优惠券。Send location-based coupons to interested user segments.
  • 向媒体/体育/财经/游戏应用程序的用户或组发送活动相关的通知。Send event-related notifications to users or groups for media/sports/finance/gaming applications.
  • 将促销内容推送到应用程序,以吸引客户并向其推销。Push promotional contents to applications to engage and market to customers.
  • 向用户通知企业事件,例如新的消息和工作项。Notify users of enterprise events such as new messages and work items.
  • 发送多重身份验证的代码。Send codes for multi-factor authentication.

什么是推送通知?What are push notifications?

推送通知是一种应用到用户的通信形式,它通常以移动设备上的弹窗或对话框的方式将某种需要的信息通知给移动应用的用户。Push notifications are a form of app-to-user communication where users of mobile apps are notified of certain desired information, usually in a pop-up or dialog box on a mobile device. 用户通常选择是要查看还是忽略该消息,如果选择前者,将打开传达了该通知的移动应用程序。Users generally choose to view or dismiss the message; choosing the former opens the mobile application that communicated the notification. 一些通知是静默通知 - 通过后台提供,以便应用进行处理和确定相应操作。Some notifications are silent - delivered behind the scenes for the app to process and decide what to do.

推送通知对于提高消费型应用的应用参与度与使用量以及在企业应用中传达最新业务信息至关重要。Push notifications are vital for consumer apps in increasing app engagement and usage, and for enterprise apps in communicating up-to-date business information. 它是最佳的应用到用户通信形式,因为它对于移动设备而言能效较高,对于发送方而言具有弹性,即使相应的应用程序处于非活动状态时,也能使用推送通知。It's the best app-to-user communication because it is energy-efficient for mobile devices, flexible for the notifications senders, and available when corresponding applications are not active.


Azure 通知中心并不正式支持 IP 语音 (VoIP) 推送通知;但是,此文介绍如何通过 Azure 通知中心使用 APNS VOIP 通知Azure Notification Hubs does not officially support Voice Over Internet Protocol (VOIP) push notifications; however, this article describes how you can use APNS VOIP notifications through Azure Notification Hubs.

有关一些流行平台中的推送通知的详细信息,请参阅以下主题:For more information on push notifications for a few popular platforms, see the following topics:

推送通知的工作原理是什么?How do push notifications work?

推送通知通过称为平台通知系统 (PNS) 的特定于平台的基础结构进行传送。Push notifications are delivered through platform-specific infrastructures called Platform Notification Systems (PNSes). 它们提供基本的推送功能,使用提供的句柄向设备传送消息,没有通用接口。They offer basic push functionalities to deliver a message to a device with a provided handle, and have no common interface. 若要跨应用的 Android、iOS 和 Windows 版本向所有客户发送通知,开发人员必须分别使用 Apple Push Notification 服务 (APNS) 和 Windows 通知服务 (WNS)。To send a notification to all customers across the Android, iOS, and Windows versions of an app, the developer must work separately with Apple Push Notification Service(APNS) and Windows Notification Service(WNS).

从较高层面讲,推送的工作原理如下:At a high level, here is how push works:

  1. 应用程序希望接收通知,因此会联系运行时所在的目标平台的 PNS 并请求唯一的临时推送句柄。An application wants to receive a notification, so it contacts the PNS for the target platform on which the app is running and requests a unique and temporary push handle. 句柄类型取决于系统(例如,WNS 使用 URI,APNS 使用令牌)。The handle type depends on the system (for example, WNS uses URIs while APNS uses tokens).
  2. 客户端应用将此句柄存储在应用后端或提供程序中。The client app stores this handle in the app backend or provider.
  3. 为了发送推送通知,应用后端使用句柄与 PNS 联系以定位到特定的客户端应用。To send a push notification, the app backend contacts the PNS using the handle to target a specific client app.
  4. PNS 将通知转发到句柄所指定的设备。The PNS forwards the notification to the device specified by the handle.


推送通知的难点The challenges of push notifications

PNSes 非常强大。PNSes are powerful. 但应用开发人员仍然需要完成大量工作才能实现常见的推送通知方案,例如,将推送通知广播给细分用户。However, they leave much work to the app developer to implement even common push notification scenarios, such as broadcasting push notifications to segmented users.

发送推送通知需要与应用程序的主要业务逻辑无关的复杂基础结构。Sending push notifications requires complex infrastructure that is unrelated to the application's main business logic. 下面是基础结构方面的一些难题:Some of the infrastructure challenges are:

  • 平台依赖性Platform dependency
    • 由于 PNS 并不统一,需要在后端中使用复杂且难以维护的平台相关逻辑,才能将通知发送到各个平台上的设备。The backend requires complex and hard-to-maintain platform-dependent logic to send notifications to devices on various platforms, as PNSes are not unified.
  • 缩放Scale
    • 根据 PNS 指导原则,每次启动应用时都必须刷新设备令牌。Per PNS guidelines, device tokens must be refreshed on every app launch. 仅仅是为了保持令牌的最新状态,后端就必须处理大量的流量和数据库访问。The backend deals with a large amount of traffic and database access just to keep the tokens up-to-date. 当设备数目增长到几亿甚至几十亿时,创建和维护此基础结构所需的成本是巨大的。When the number of devices grows to hundreds, thousands, or millions, the cost of creating and maintaining this infrastructure is massive.
    • 大多数 PNS 不支持广播到多台设备。Most PNSes do not support broadcast to multiple devices. 仅仅是广播到 100 万台设备就需要对 PNS 发出 100 万次调用。A simple broadcast to a million devices results in a million calls to the PNSes. 以最低的延迟缩放这种流量大小并非易事。Scaling this amount of traffic with minimal latency is nontrivial.
  • 路由Routing
    • 尽管 PNS 提供了向设备发送消息的方式,但大多数应用通知面向用户或兴趣组。Though PNSes provide a way to send messages to devices, most app notifications are targeted at users or interest groups. 后端必须维护一个注册表,用于将设备与兴趣组、用户、属性等关联起来。此项开销增大了应用的面市时间和维护成本。The backend must maintain a registry to associate devices with interest groups, users, properties, etc. This overhead adds to the time to market and maintenance costs of an app.

为何使用 Azure 通知中心?Why use Azure Notification Hubs?

通知中心消除了与你自行从应用后端发送推送通知相关的所有复杂性。Notification Hubs eliminates all complexities associated with sending push notifications on your own from your app backend. 它的多平台扩展式推送通知基础结构减少了推送相关的代码并简化了后端。Its multi-platform, scaled-out push notification infrastructure reduces push-related coding and simplifies your backend. 使用通知中心时,设备只负责将其 PNS 句柄注册到中心,而后端负责向用户或兴趣组发送消息,如下图中所示:With Notification Hubs, devices are merely responsible for registering their PNS handles with a hub, while the backend sends messages to users or interest groups, as shown in the following figure:


通知中心是随时可用的推送引擎,具有以下优点:Notification Hubs is your ready-to-use push engine with the following advantages:

  • 跨平台Cross platforms
    • 支持所有主要的推送平台。Support for all major push platforms.
    • 有一个通用接口,可以使用平台特定的或平台相关的格式向所有平台推送通知,无需执行平台特定的工作。A common interface to push to all platforms in platform-specific or platform-independent formats with no platform-specific work.
    • 在一个位置管理设备句柄。Device handle management in one place.
  • 跨后端Cross backends
    • 云或本地。Cloud or on-premises.
    • .NET、Node.js、Java、Python 等。.NET, Node.js, Java, Python, etc.
  • 丰富的传送模式集Rich set of delivery patterns
    • 广播到一个或多个平台:只需调用 API 一次,便可立即广播到数百万台跨平台设备。Broadcast to one or more platforms: You can instantly broadcast to millions of devices across platforms with a single API call.
    • 推送到设备:可将通知定位到单个设备。Push to device: You can target notifications to individual devices.
    • 推送到用户:可以借助标记和模板将通知传入用户的所有跨平台设备。Push to user: Tags and templates help you reach all cross-platform devices for a user.
    • 使用动态标记推送到目标段:可以借助标记功能根据需要将设备分段并向其推送通知,不管是要发送到一个段还是段的表达式(例如,active AND lives in Seattle NOT new user)。Push to segment with dynamic tags: The tags feature helps you segment devices and push to them according to your needs, whether you are sending to one segment or an expression of segments (For example, active AND lives in Seattle NOT new user). 可以不受发布-订阅的限制,随时随地更新设备标记。Instead of being restricted to publish-subscribe, you can update device tags anywhere and anytime.
    • 本地化推送:可以借助模板功能实现本地化,而不会影响到后端代码。Localized push: The templates feature helps achieve localization without affecting backend code.
    • 静默推送:可以通过向设备发送静默通知并触发设备完成特定的拉取或操作,来实现推送-拉取模式。Silent push: You can enable the push-to-pull pattern by sending silent notifications to devices and triggering them to complete certain pulls or actions.
    • 计划推送:可以按计划随时发送通知。Scheduled push: You can schedule notifications to be sent anytime.
    • 直接推送:可以跳过将设备注册到通知中心服务的步骤,直接批量推送到设备句柄列表。Direct push: You can skip registering devices with the Notification Hubs service and directly batch push to a list of device handles.
    • 个性化推送:可以借助设备推送变量,使用自定义的键值对发送设备特定的个性化推送通知。Personalized push: Device push variables help you send device-specific personalized push notifications with customized key-value pairs.
  • 丰富的遥测Rich telemetry
    • 可通过 Azure 门户和编程方式使用常规的推送、设备、错误和操作遥测。General push, device, error, and operation telemetry are available both in the Azure portal and programmatically.
    • 单消息遥测会跟踪从发出初始请求调用到通知中心服务成功发送推送的每个推送过程。Per-message telemetry tracks each push from your initial request call to the Notification Hubs service successfully sending the pushes.
    • 平台通知系统反馈会传达来自 PNS 的所有反馈以帮助调试。Platform Notification System feedback communicates all feedback from PNSes to assist in debugging.
  • 伸缩性Scalability
    • 无需重建体系结构或者将设备分片,即可快速地向数百万台设备发送消息。Send fast messages to millions of devices without re-architecting or device sharding.
  • 安全性Security
    • 共享访问机密 (SAS) 或联合身份验证。Shared Access Secret (SAS) or federated authentication.

后续步骤Next steps

按照教程:向移动应用程序推送通知,开始创建和使用通知中心。Get started with creating and using a notification hub by following the Tutorial: Push notifications to mobile applications.