Skip to content

Commit 4fcf25b

Browse files
authored
add client traffic control for signalr
1 parent 9146177 commit 4fcf25b

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

articles/azure-signalr/signalr-howto-configure-application-firewall.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The Application Firewall provides sophisticated control over client connections
1717

1818
## What Does the Application Firewall Do?
1919

20-
The Application Firewall consists of various rule lists. Currently, there is a rule list called *Client Connection Count Rules*. Future updates will support more rule lists to control aspects like connection lifetime and message throughput.
20+
The Application Firewall consists of various rule lists. Currently, there are two rule lists called *Client Connection Count Rules* and *Client Traffic Control Rules*. Future updates will support more rule lists to control aspects such as connection lifetime.
2121

2222
This guideline is divided into three parts:
2323
1. Introduction to different application firewall rules.
@@ -56,7 +56,18 @@ Client Connection Count Rules restrict concurrent client connections. When a cli
5656
> [!WARNING]
5757
> * **Avoid using too aggressive maxCount**. Client connections may close without completing the TCP handshake. SignalR service can't detect those "half-closed" connections immediately. The connection is taken as active until the heartbeat failure. Therefore, aggressive throttling strategies might unexpectedly throttle clients. A smoother approach is to **leave some buffer** for the connection count, for example: double the *maxCount*.
5858
59+
## Client Traffic Control Rules
60+
Client Traffic Control Rules restrict the inbound throughput of client connections. When a client attempts to send a message, the rules are checked **sequentially**. Within each *aggregation window*, the message size will be aggregated to check against *max inbound message*. If any rule is violated, the connection is disconnected.
5961

62+
#### TrafficThrottleByUserIdRule
63+
This rule limits the inbound throughput of a user.
64+
65+
#### TrafficThrottleByJwtSignatureRule
66+
This rule limits the inbound throughput of each token.
67+
68+
#### TrafficThrottleByJwtCustomClaimRule
69+
This rule limits the inbound throughput of the same claim.
70+
6071

6172
## Set up Application Firewall
6273

@@ -73,7 +84,7 @@ Use Visual Studio Code or your favorite editor to create a file with the followi
7384
@description('The name for your SignalR service')
7485
param resourceName string = 'contoso'
7586
76-
resource signalr 'Microsoft.SignalRService/signalr@2024-04-01-preview' = {
87+
resource signalr 'Microsoft.SignalRService/signalr@2024-10-01-preview' = {
7788
name: resourceName
7889
properties: {
7990
applicationFirewall:{
@@ -101,6 +112,42 @@ resource signalr 'Microsoft.SignalRService/signalr@2024-04-01-preview' = {
101112
claimName: 'paidUser'
102113
}
103114
]
115+
clientTrafficControlRules:[
116+
// Add or remove rules as needed
117+
{
118+
// This rule will be skipped if no userId is set
119+
type: 'TrafficThrottleByUserIdRule'
120+
// Every minute
121+
aggregationWindowInSeconds: 60
122+
// 10MB
123+
maxInboundMessageBytes: 10485760
124+
}
125+
{
126+
type: 'TrafficThrottleByJwtSignatureRule'
127+
// Every 30 seconds
128+
aggregationWindowInSeconds: 30
129+
// 5MB
130+
maxInboundMessageBytes: 5242880
131+
}
132+
{
133+
// This rule will be skipped if no freeUser claim is set
134+
type: 'TrafficThrottleByJwtCustomClaimRule'
135+
// Every 10 minutes
136+
aggregationWindowInSeconds: 600
137+
// 1MB
138+
maxInboundMessageBytes: 1048576
139+
claimName: 'freeUser'
140+
}
141+
{
142+
// This rule will be skipped if no paidUser claim is set
143+
type: 'TrafficThrottleByJwtCustomClaimRule'
144+
// Every 30 seconds
145+
aggregationWindowInSeconds: 30
146+
// 1MB
147+
maxInboundMessageBytes: 1048576
148+
claimName: 'paidUser'
149+
}
150+
]
104151
}
105152
}
106153
}

0 commit comments

Comments
 (0)