|
1 | 1 | ---
|
2 | 2 | title: Service mode in Azure SignalR Service
|
3 |
| -description: An overview of different service modes in Azure SignalR Service, explain their differences and applicable user scenarios |
| 3 | +description: An overview of service modes in Azure SignalR Service. |
4 | 4 | author: vicancy
|
5 | 5 | ms.service: signalr
|
6 | 6 | ms.topic: conceptual
|
7 |
| -ms.date: 08/19/2020 |
| 7 | +ms.date: 09/01/2022 |
8 | 8 | ms.author: lianwei
|
9 | 9 | ---
|
10 | 10 | # Service mode in Azure SignalR Service
|
11 | 11 |
|
12 |
| -Service mode is an important concept in Azure SignalR Service. When you create a new SignalR resource, you will be asked to specify a service mode: |
| 12 | +Service mode is an important concept in Azure SignalR Service. SignalR Service currently supports three service modes: *Default*, *Serverless*, and *Classic*. Your SignalR Service resource will behave differently in each mode. In this article, you'll learn how to choose the right service mode based on your scenario. |
13 | 13 |
|
14 |
| -:::image type="content" source="media/concept-service-mode/create.png" alt-text="Choose service mode when create"::: |
| 14 | +## Setting the service mode |
15 | 15 |
|
16 |
| -You can also change it later in the settings menu: |
| 16 | +You'll be asked to specify a service mode when you create a new SignalR resource in the Azure portal. |
| 17 | + |
| 18 | +:::image type="content" source="media/concept-service-mode/create.png" alt-text="Azure portal – Choose service mode when creating a SignalR Service"::: |
| 19 | + |
| 20 | +You can also change the service mode later in the settings menu. |
17 | 21 |
|
18 | 22 | :::image type="content" source="media/concept-service-mode/update.png" alt-text="Update service mode":::
|
19 | 23 |
|
20 |
| -Azure SignalR Service currently supports three service modes: **default**, **serverless** and **classic**. Your SignalR resource will behave differently in different modes. In this article, you'll learn their differences and how to choose the right service mode based on your scenario. |
| 24 | +Use `az signalr create` and `az signalr update` to set or change the service mode by using the [Azure SignalR CLI](/cli/azure/service-page/azure%20signalr). |
21 | 25 |
|
22 | 26 | ## Default mode
|
23 | 27 |
|
24 |
| -Default mode is the default value for service mode when you create a new SignalR resource. In this mode, your application works as a typical ASP.NET Core (or ASP.NET) SignalR application, where you have a web server that hosts a hub (called hub server hereinafter) and clients can have duplex real-time communication with the hub server. The only difference is instead of connecting client and server directly, client and server both connect to SignalR service and use the service as a proxy. Below is a diagram that illustrates the typical application structure in default mode: |
| 28 | +As the name implies, *Default* mode is the default service mode for SignalR Service. In Default mode, your application works as a typical [ASP.NET Core SignalR](/aspnet/core/signalr/introduction) or ASP.NET SignalR (deprecated) application. You have a web server application that hosts a hub, called a *hub server*, and clients have full duplex communication with the hub server. The difference between ASP.NET Core SignalR and Azure SignalR Service is instead of connecting client and hub server directly, client and server both connect to SignalR Service and use the service as a proxy. The following diagram shows the typical application structure in Default mode. |
25 | 29 |
|
26 |
| -:::image type="content" source="media/concept-service-mode/default.png" alt-text="Application structure in default mode"::: |
| 30 | +:::image type="content" source="media/concept-service-mode/default.png" alt-text="Application structure in Default mode"::: |
27 | 31 |
|
28 |
| -So if you have a SignalR application and want to integrate with SignalR service, default mode should be the right choice for most cases. |
| 32 | +Default mode is usually the right choice when you have a SignalR application that you want to use with SignalR Service. |
29 | 33 |
|
30 |
| -### Connection routing in default mode |
| 34 | +### Connection routing in Default mode |
31 | 35 |
|
32 |
| -In default mode, there will be websocket connections between hub server and SignalR service (called server connections). These connections are used to transfer messages between server and client. When a new client is connected, SignalR service will route the client to one hub server (assume you have more than one server) through existing server connections. Then the client connection will stick to the same hub server during its lifetime. When client sends messages, they always go to the same hub server. With this behavior, you can safely maintain some states for individual connections on your hub server. For example, if you want to stream something between server and client, you don't need to consider the case that data packets go to different servers. |
| 36 | +In Default mode, there are WebSocket connections between hub server and SignalR Service called *server connections*. These connections are used to transfer messages between a server and client. When a new client is connected, SignalR Service will route the client to one hub server (assume you've more than one server) through existing server connections. The client connection will stick to the same hub server during its lifetime. This property is referred to as *connection stickiness*. When the client sends messages, they always go to the same hub server. With stickiness behavior, you can safely maintain some states for individual connections on your hub server. For example, if you want to stream something between server and client, you don't need to consider the case where data packets go to different servers. |
33 | 37 |
|
34 | 38 | > [!IMPORTANT]
|
35 |
| -> This also means in default mode a client cannot connect without server being connected first. If all your hub servers are disconnected due to network interruption or server reboot, your client connections will get an error telling you no server is connected. So it's your responsibility to make sure at any time there is at least one hub server connected to SignalR service (for example, have multiple hub servers and make sure they won't go offline at the same time for things like maintenance). |
| 39 | +> In Default mode a client cannot connect without a hub server being connected to the service first. If all your hub servers are disconnected due to network interruption or server reboot, your client connections will get an error telling you no server is connected. It's your responsibility to make sure there is always at least one hub server connected to SignalR service. For example, you can design your application with multiple hub servers, and then make sure they won't all go offline at the same time. |
36 | 40 |
|
37 |
| -This routing model also means when a hub server goes offline, the connections routed that server will be dropped. So you should expect connection drop when your hub server is offline for maintenance and handle reconnect properly so that it won't have negative impact to your application. |
| 41 | +The default routing model also means when a hub server goes offline, the connections routed to that server will be dropped. You should expect connections to drop when your hub server is offline for maintenance, and handle reconnection to minimize the effects on your application. |
| 42 | + |
| 43 | +> [!NOTE] |
| 44 | +> In Default mode you can also use REST API, management SDK, and function binding to directly send messages to a client if you don't want to go through a hub server. In Default mode client connections are still handled by hub servers and upstream endpoints won't work in that mode. |
38 | 45 |
|
39 | 46 | ## Serverless mode
|
40 | 47 |
|
41 |
| -In Serverless mode, you don't have a hub server. Unlike default mode, the client doesn't require a hub server to be running. All connections are connected in a "serverless" mode and the Azure SignalR service is responsible for maintaining client connections like handling client pings (in default mode this is handled by hub servers). |
| 48 | +Unlike Default mode, Serverless mode doesn't require a hub server to be running, which is why this mode is named "serverless." SignalR Service is responsible for maintaining client connections. There's no guarantee of connection stickiness and HTTP requests may be less efficient than WebSockets connections. |
| 49 | + |
| 50 | +Serverless mode works with Azure Functions to provide real time messaging capability. Clients work with [SignalR Service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md), called *function binding*, to send messages as an output binding. |
42 | 51 |
|
43 |
| -Also there is no server connection in this mode (if you try to use service SDK to establish server connection, you will get an error). Therefore there is also no connection routing and server-client stickiness (as described in the default mode section). But you can still have server-side application to push messages to clients. This can be done in two ways, use [REST APIs](https://github.com/Azure/azure-signalr/blob/dev/docs/rest-api.md) for one-time send, or through a websocket connection so that you can send multiple messages more efficiently (note this websocket connection is different than server connection). |
| 52 | +Because there's no server connection, if you try to use a server SDK to establish a server connection you'll get an error. SignalR Service will reject server connection attempts in Serverless mode. |
| 53 | + |
| 54 | +Serverless mode doesn't have connection stickiness, but you can still have a server-side application push messages to clients. There are two ways to push messages to clients in Serverless mode: |
| 55 | + |
| 56 | +- Use [REST APIs](https://github.com/Azure/azure-signalr/blob/dev/docs/rest-api.md) for a one-time send event, or |
| 57 | +- Use a WebSocket connection so that you can send multiple messages more efficiently. This WebSocket connection is different than a server connection. |
44 | 58 |
|
45 | 59 | > [!NOTE]
|
46 |
| -> Both REST API and websocket way are supported in SignalR service [management SDK](https://github.com/Azure/azure-signalr/blob/dev/docs/management-sdk-guide.md). If you're using a language other than .NET, you can also manually invoke the REST APIs following this [spec](https://github.com/Azure/azure-signalr/blob/dev/docs/rest-api.md). |
47 |
| -> |
48 |
| -> If you're using Azure Functions, you can use [SignalR service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md) (hereinafter called function binding) to send messages as an output binding. |
| 60 | +> Both REST API and WebSockets are supported in SignalR service [management SDK](https://github.com/Azure/azure-signalr/blob/dev/docs/management-sdk-guide.md). If you're using a language other than .NET, you can also manually invoke the REST APIs following this [specification](https://github.com/Azure/azure-signalr/blob/dev/docs/rest-api.md). |
49 | 61 |
|
50 |
| -It's also possible for your server application to receive messages and connection events from clients. Service will deliver messages and connection events to preconfigured endpoints (called Upstream) using webhooks. Comparing to default mode, there is no guarantee of stickiness and HTTP requests may be less efficient than websocket connections. |
| 62 | +It's also possible for your server application to receive messages and connection events from clients. SignalR Service will deliver messages and connection events to pre-configured endpoints (called *upstream endpoints*) using web hooks. Upstream endpoints can only be configured in Serverless mode. For more information, see [Upstream settings](concept-upstream.md). |
51 | 63 |
|
52 |
| -For more information about how to configure upstream, see this [doc](./concept-upstream.md). |
53 | 64 |
|
54 |
| -Below is a diagram that illustrates how serverless mode works: |
55 | 65 |
|
56 |
| -:::image type="content" source="media/concept-service-mode/serverless.png" alt-text="Application structure in serverless mode"::: |
| 66 | +The following diagram shows how Serverless mode works. |
57 | 67 |
|
58 |
| -> [!NOTE] |
59 |
| -> Please note in default mode you can also use REST API/management SDK/function binding to directly send messages to client if you don't want to go through hub server. But in default mode client connections are still handled by hub servers and upstream won't work in that mode. |
| 68 | +:::image type="content" source="media/concept-service-mode/serverless.png" alt-text="Application structure in Serverless mode"::: |
60 | 69 |
|
61 | 70 | ## Classic mode
|
62 | 71 |
|
63 |
| -Classic is a mixed mode of default and serverless mode. In this mode, connection mode is decided by whether there is hub server connected when client connection is established. If there is hub server, client connection will be routed to a hub server. Otherwise it will enter a serverless mode where client to server message cannot be delivered to hub server. This will cause some discrepancies, for example if all hub servers are unavailable for a short time, all client connections created during that time will be in serverless mode and cannot send messages to hub server. |
64 |
| - |
65 | 72 | > [!NOTE]
|
66 |
| -> Classic mode is mainly for backward compatibility for those applications created before there is default and serverless mode. It's strongly recommended to not use this mode anymore. For new applications, please choose default or serverless based on your scenario. For existing applications, it's also recommended to review your use cases and choose a proper service mode. |
| 73 | +> Classic mode is mainly for backward compatibility for applications created before the Default and Serverless modes were introduced. Don't use Classic mode except as a last resort. Use Default or Serverless for new applications, based on your scenario. You should consider redesigning existing applications to eliminate the need for Classic mode. |
| 74 | +
|
| 75 | +Classic is a mixed mode of Default and Serverless modes. In Classic mode, connection type is decided by whether there's a hub server connected when the client connection is established. If there's a hub server, the client connection will be routed to a hub server. If a hub server isn't available, the client connection will be made in a limited serverless mode where client-to-server messages can't be delivered to a hub server. Classic mode serverless connections don't support some features such as upstream endpoints. |
67 | 76 |
|
68 |
| -Classic mode also doesn't support some new features like upstream in serverless mode. |
| 77 | +If all your hub servers are offline for any reason, connections will be made in Serverless mode. It's your responsibility to ensure that at least one hub server is always available. |
69 | 78 |
|
70 | 79 | ## Choose the right service mode
|
71 | 80 |
|
72 |
| -Now you should understand the differences between service modes and know how to choose between them. As you already learned in the previous section, classic mode is not encouraged and you should only choose between default and serverless. Here are some more tips that can help you make the right choice for new applications and retire classic mode for existing applications. |
| 81 | +Now you should understand the differences between service modes and know how to choose between them. As previously discussed, Classic mode isn't recommended for new or existing applications. Here are some more tips that can help you make the right choice for service mode and help you retire Classic mode for existing applications. |
73 | 82 |
|
74 |
| -* If you're already familiar with how SignalR library works and want to move from a self-hosted SignalR to use Azure SignalR Service, choose default mode. Default mode works exactly the same way as self-hosted SignalR (and you can use the same programming model in SignalR library), SignalR service just acts as a proxy between clients and hub servers. |
| 83 | +- Choose Default mode if you're already familiar with how SignalR library works and want to move from a self-hosted SignalR to use Azure SignalR Service. Default mode works exactly the same way as self-hosted SignalR, and you can use the same programming model in SignalR library. SignalR Service acts as a proxy between clients and hub servers. |
75 | 84 |
|
76 |
| -* If you're creating a new application and don't want to maintain hub server and server connections, choose serverless mode. This mode usually works together with Azure Functions so you don't need to maintain any server at all. You can still have duplex communications (with REST API/management SDK/function binding + upstream) but the programming model will be different than SignalR library. |
| 85 | +- Choose Serverless mode if you're creating a new application and don't want to maintain hub server and server connections. Serverless mode works together with Azure Functions so that you don't need to maintain any server at all. You can still have full duplex communications with REST API, management SDK, or function binding + upstream endpoint, but the programming model will be different than SignalR library. |
77 | 86 |
|
78 |
| -* If you have both hub servers to serve client connections and backend application to directly push messages to clients (for example through REST API), you should still choose default mode. Keep in mind that the key difference between default and serverless mode is whether you have hub servers and how client connections are routed. REST API/management SDK/function binding can be used in both modes. |
| 87 | +- Choose Default mode if you have *both* hub servers to serve client connections and a backend application to directly push messages to clients. The key difference between Default and Serverless mode is whether you have hub servers and how client connections are routed. REST API/management SDK/function binding can be used in both modes. |
79 | 88 |
|
80 |
| -* If you really have a mixed scenario, for example, you have two different hubs on the same SignalR resource, one used as a traditional SignalR hub and the other one used with Azure Functions and doesn't have hub server, you should really consider to separate them into two SignalR resources, one in default mode and one in serverless mode. |
| 89 | +- If you really have a mixed scenario, you should consider separating use cases into multiple SignalR Service instances with service mode set according to use. An example of a mixed scenario that requires Classic mode is where you have two different hubs on the same SignalR resource. One hub is used as a traditional SignalR hub and the other hub is used with Azure Functions. This example should be split into two resources, with one instance in Default mode and one in Serverless mode. |
81 | 90 |
|
82 | 91 | ## Next steps
|
83 | 92 |
|
84 |
| -To learn more about how to use default and serverless mode, read the following articles: |
| 93 | +See the following articles to learn more about how to use Default and Serverless modes. |
85 | 94 |
|
86 |
| -* [Azure SignalR Service internals](signalr-concept-internals.md) |
| 95 | +- [Azure SignalR Service internals](signalr-concept-internals.md) |
87 | 96 |
|
88 |
| -* [Azure Functions development and configuration with Azure SignalR Service](signalr-concept-serverless-development-config.md) |
| 97 | +- [Azure Functions development and configuration with Azure SignalR Service](signalr-concept-serverless-development-config.md) |
0 commit comments