Skip to content

Commit c41c156

Browse files
Merge pull request #271004 from Y-Sindo/patch-4
Update signalr trigger docs
2 parents 46c109d + 60642f4 commit c41c156

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

articles/azure-functions/functions-bindings-signalr-service-trigger.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ See [Class based model](../azure-signalr/signalr-concept-serverless-development-
5050
public class HubName1 : ServerlessHub
5151
{
5252
[FunctionName("SignalRTest")]
53-
public async Task SendMessage([SignalRTrigger]InvocationContext invocationContext, string message, ILogger logger)
53+
public Task SendMessage([SignalRTrigger]InvocationContext invocationContext, string message, ILogger logger)
5454
{
5555
logger.LogInformation($"Receive {message} from {invocationContext.ConnectionId}.");
5656
}
@@ -63,7 +63,7 @@ Traditional model obeys the convention of Azure Function developed by C#. If you
6363

6464
```cs
6565
[FunctionName("SignalRTest")]
66-
public static async Task Run([SignalRTrigger("SignalRTest", "messages", "SendMessage", parameterNames: new string[] {"message"})]InvocationContext invocationContext, string message, ILogger logger)
66+
public static Task Run([SignalRTrigger("SignalRTest", "messages", "SendMessage", parameterNames: new string[] {"message"})]InvocationContext invocationContext, string message, ILogger logger)
6767
{
6868
logger.LogInformation($"Receive {message} from {invocationContext.ConnectionId}.");
6969
}
@@ -73,7 +73,7 @@ Because it can be hard to use `ParameterNames` in the trigger, the following exa
7373

7474
```cs
7575
[FunctionName("SignalRTest")]
76-
public static async Task Run([SignalRTrigger("SignalRTest", "messages", "SendMessage")]InvocationContext invocationContext, [SignalRParameter]string message, ILogger logger)
76+
public static Task Run([SignalRTrigger("SignalRTest", "messages", "SendMessage")]InvocationContext invocationContext, [SignalRParameter]string message, ILogger logger)
7777
{
7878
logger.LogInformation($"Receive {message} from {invocationContext.ConnectionId}.");
7979
}
@@ -113,7 +113,7 @@ app.generic("function1",
113113
Here's the JavaScript code:
114114

115115
```javascript
116-
module.exports = async function (context, invocation) {
116+
module.exports = function (context, invocation) {
117117
context.log(`Receive ${context.bindingData.message} from ${invocation.ConnectionId}.`)
118118
};
119119
```

articles/azure-signalr/signalr-concept-serverless-development-config.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ The class-based model is dedicated for C#.
7676
The class-based model provides better programming experience, which can replace SignalR input and output bindings, with the following features:
7777
- More flexible negotiation, sending messages and managing groups experience.
7878
- More managing functionalities are supported, including closing connections, checking whether a connection, user, or group exists.
79-
- Strongly Typed hub
80-
- Unified connection string setting in one place.
79+
- Strongly typed hub
80+
- Unified hub name and connection string setting in one place.
8181

8282
The following code demonstrates how to write SignalR bindings in class-based model:
8383

84-
In the *Functions.cs* file, define your hub, which extends a base class `ServerlessHub`:
84+
Firstly, define your hub derived from a class `ServerlessHub`:
8585
```cs
8686
[SignalRConnection("AzureSignalRConnectionString")]
8787
public class Functions : ServerlessHub
8888
{
89-
private const string HubName = nameof(Functions);
89+
private const string HubName = nameof(Functions); // Used by SignalR trigger only
9090
9191
public Functions(IServiceProvider serviceProvider) : base(serviceProvider)
9292
{
@@ -126,7 +126,7 @@ var host = new HostBuilder()
126126

127127
### Negotiation experience in class-based model
128128

129-
Instead of using SignalR input binding `[SignalRConnectionInfoInput]`, negotiation in class-based model can be more flexible. Base class `ServerlessHub` has a method `NegotiateAsync`, which allows user to customize negotiation options such as `userId`, `claims`, etc.
129+
Instead of using SignalR input binding `[SignalRConnectionInfoInput]`, negotiation in class-based model can be more flexible. Base class `ServerlessHub` has a method `NegotiateAsync`, which allows users to customize negotiation options such as `userId`, `claims`, etc.
130130

131131
```cs
132132
Task<BinaryData> NegotiateAsync(NegotiationOptions? options = null)
@@ -141,7 +141,7 @@ You could send messages, manage groups, or manage clients by accessing the membe
141141
- `ServerlessHub.UserGroups` for managing users with groups, such as adding users to groups, removing users from groups.
142142
- `ServerlessHub.ClientManager` for checking connections existence, closing connections, etc.
143143

144-
### Strongly Typed Hub
144+
### Strongly typed Hub
145145

146146
[Strongly typed hub](/aspnet/core/signalr/hubs?#strongly-typed-hubs) allows you to use strongly typed methods when you send messages to clients. To use strongly typed hub in class based model, extract client methods into an interface `T`, and make your hub class derived from `ServerlessHub<T>`.
147147

@@ -158,7 +158,7 @@ Then you can use the strongly typed methods as follows:
158158
[SignalRConnection("AzureSignalRConnectionString")]
159159
public class Functions : ServerlessHub<IChatClient>
160160
{
161-
private const string HubName = nameof(Functions);
161+
private const string HubName = nameof(Functions); // Used by SignalR trigger only
162162
163163
public Functions(IServiceProvider serviceProvider) : base(serviceProvider)
164164
{
@@ -176,18 +176,18 @@ public class Functions : ServerlessHub<IChatClient>
176176
> [!NOTE]
177177
> You can get a complete project sample from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/DotnetIsolated-ClassBased/).
178178
179-
### Unified connection string setting in one place
179+
### Unified hub name and connection string setting in one place
180180

181-
You might have noticed the `SignalRConnection` attribute used on serverless hub classes. It looks like this:
182-
```cs
183-
[SignalRConnection("AzureSignalRConnectionString")]
184-
public class Functions : ServerlessHub<IChatClient>
185-
```
186-
187-
It allows you to customize where the SignalR Service bindings look for connection string. If it's absent, the default value `AzureSignalRConnectionString` is used.
181+
* The class name of the serverless hub is automatically used as `HubName`.
182+
* You might have noticed the `SignalRConnection` attribute used on serverless hub classes as follows:
183+
```cs
184+
[SignalRConnection("AzureSignalRConnectionString")]
185+
public class Functions : ServerlessHub<IChatClient>
186+
```
187+
It allows you to customize where the connection string for serverless hub is. If it's absent, the default value `AzureSignalRConnectionString` is used.
188188

189189
> [!IMPORTANT]
190-
> `SignalRConnection` attribute doesn't change the connection string setting of SignalR triggers, even though you use SignalR triggers inside the serverless hub. You should specify the connection string setting for each SignalR trigger if you want to customize it.
190+
> SignalR triggers and serverless hubs are independent. Therefore, the class name of serverless hub and `SignalRConnection` attribute doesn't change the settings of SignalR triggers, even though you use SignalR triggers inside the serverless hub.
191191

192192
# [In-process model](#tab/in-process)
193193

@@ -229,7 +229,7 @@ public class HubName1 : ServerlessHub
229229
}
230230
```
231231

232-
All functions that want to use the class-based model need to be a method of the class that inherits from **ServerlessHub**. The class name `SignalRTestHub` in the sample is the hub name.
232+
All functions that want to use the class-based model need to be a method of the class that inherits from **ServerlessHub**. The class name `HubName1` in the sample is the hub name.
233233

234234
### Define hub method
235235

@@ -250,13 +250,13 @@ In class based model, `[SignalRParameter]` is unnecessary because all the argume
250250

251251
### Negotiation experience in class-based model
252252

253-
Instead of using SignalR input binding `[SignalR]`, negotiation in class-based model can be more flexible. Base class `ServerlessHub` has a method.
253+
Instead of using SignalR input binding `[SignalR]`, negotiation in class-based model can be more flexible. Base class `ServerlessHub` has a method:
254254

255255
```cs
256256
SignalRConnectionInfo Negotiate(string userId = null, IList<Claim> claims = null, TimeSpan? lifeTime = null)
257257
```
258258

259-
This features user customizes `userId` or `claims` during the function execution.
259+
This feature allows user to customize `userId` or `claims` during the function execution.
260260

261261
## Use `SignalRFilterAttribute`
262262

0 commit comments

Comments
 (0)