Skip to content

Commit b289de9

Browse files
authored
Merge pull request #175768 from zackliu/ackidrefactor
[WebPubSub] Update client-protocols to add ack related content
2 parents ff07bb8 + 4a52446 commit b289de9

File tree

3 files changed

+66
-16
lines changed

3 files changed

+66
-16
lines changed

articles/azure-web-pubsub/concept-client-protocols.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,47 @@ As you likely noticed in the earlier PubSub WebSocket client description, a clie
8686
| `webpubsub.sendToGroup.<group>` | The client can publish messages to group `<group>`. |
8787
| | |
8888

89+
## AckId and Ack Response
90+
91+
The PubSub WebSocket Client supports `ackId` property for `joinGroup`, `leaveGroup`, `sendToGroup` and `event` messages. When using `ackId`, you can receive an ack response message when your request is processed. You can choose to omit `ackId` in fire-and-forget scenarios. In the article, we describe the behavior differences between specifying `ackId` or not.
92+
93+
### Behavior when No `ackId` specified
94+
95+
If `ackId` is not specified, it's fire-and-forget. Even there're errors when brokering messages, you have no way to get notified.
96+
97+
### Behavior when `ackId` specified
98+
99+
#### Idempotent publish
100+
101+
`ackId` is a uint64 number and should be unique within a client with the same connection id. Web PubSub Service records the `ackId` and messages with the same `ackId` will be treated as the same message. The service refuses to broker the same message more than once, which is useful in retry to avoid duplicated messages. For example, if a client sends a message with `ackId=5` and fails to receive an ack response with `ackId=5`, then the client retries and sends the same message again. In some cases, the message is already brokered and the ack response is lost for some reason, the service will reject the retry and response an ack response with `Duplicate` reason.
102+
103+
#### Ack Response
104+
105+
Web PubSub Service sends ack response for each request with `ackId`.
106+
107+
Format:
108+
```json
109+
{
110+
"type": "ack",
111+
"ackId": 1, // The ack id for the request to ack
112+
"success": false, // true or false
113+
"error": {
114+
"name": "Forbidden|InternalServerError|Duplicate",
115+
"message": "<error_detail>"
116+
}
117+
}
118+
```
119+
120+
* The `ackId` associates the request.
121+
122+
* `success` is a bool and indicate whether the request is successfully processed by the service. If it is `false`, clients need to check the `error`.
123+
124+
* `error` only exists when `success` is `false` and clients should have different logic for different `name`. You should suppose there might be more type of `name` in future.
125+
- `Forbidden`: The client doesn't have the permission to the request. The client needs to be added relevant roles.
126+
- `InternalServerError`: Some internal error happened in the service. Retry is required.
127+
- `Duplicate`: The message with the same `ackId` has been already processed by the service.
128+
129+
89130
For more information about the JSON subprotocol, see [JSON subprotocol](./reference-json-webpubsub-subprotocol.md).
90131

91132
For more information about the protobuf subprotocol, see [Protobuf subprotocol](./reference-protobuf-webpubsub-subprotocol.md).

articles/azure-web-pubsub/reference-json-webpubsub-subprotocol.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ Format:
4949
{
5050
"type": "joinGroup",
5151
"group": "<group_name>",
52-
"ackId" : 1 // optional
52+
"ackId" : 1
5353
}
5454
```
5555

56-
* `ackId` is optional, it's an incremental integer for this command message. When the `ackId` is specified, the service sends a [ack response message](#ack-response) back to the client when the command is executed.
56+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
5757

5858
### Leave groups
5959

@@ -63,11 +63,11 @@ Format:
6363
{
6464
"type": "leaveGroup",
6565
"group": "<group_name>",
66-
"ackId" : 1 // optional
66+
"ackId" : 1
6767
}
6868
```
6969

70-
* `ackId` is optional, it's an incremental integer for this command message. When the `ackId` is specified, the service sends a [ack response message](#ack-response) back to the client when the command is executed.
70+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
7171

7272
### Publish messages
7373

@@ -77,14 +77,14 @@ Format:
7777
{
7878
"type": "sendToGroup",
7979
"group": "<group_name>",
80-
"ackId" : 1, // optional
80+
"ackId" : 1,
8181
"noEcho": true|false,
8282
"dataType" : "json|text|binary",
8383
"data": {}, // data can be string or valid json token depending on the dataType
8484
}
8585
```
8686

87-
* `ackId` is optional, it's an incremental integer for this command message. When the `ackId` is specified, the service sends a [ack response message](#ack-response) back to the client when the command is executed.
87+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
8888
* `noEcho` is optional. If set to true, this message is not echoed back to the same connection. If not set, the default value is false.
8989
* `dataType` can be one of `json`, `text`, or `binary`:
9090
* `json`: `data` can be any type that JSON supports and will be published as what it is; If `dataType` isn't specified, it defaults to `json`.
@@ -97,7 +97,8 @@ Format:
9797
"type": "sendToGroup",
9898
"group": "<group_name>",
9999
"dataType" : "text",
100-
"data": "text data"
100+
"data": "text data",
101+
"ackId": 1
101102
}
102103
```
103104

@@ -146,7 +147,8 @@ Format:
146147
"type": "sendToGroup",
147148
"group": "<group_name>",
148149
"dataType" : "binary",
149-
"data": "<base64_binary>"
150+
"data": "<base64_binary>",
151+
"ackId": 1
150152
}
151153
```
152154

@@ -170,11 +172,14 @@ Format:
170172
{
171173
"type": "event",
172174
"event": "<event_name>",
175+
"ackId": 1,
173176
"dataType" : "json|text|binary",
174177
"data": {}, // data can be string or valid json token depending on the dataType
175178
}
176179
```
177180

181+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
182+
178183
`dataType` can be one of `text`, `binary`, or `json`:
179184
* `json`: data can be any type json supports and will be published as what it is; If `dataType` is not specified, it defaults to `json`.
180185
* `text`: data should be in string format, and the string data will be published;
@@ -185,6 +190,7 @@ Format:
185190
{
186191
"type": "event",
187192
"event": "<event_name>",
193+
"ackId": 1,
188194
"dataType" : "text",
189195
"data": "text data",
190196
}
@@ -218,6 +224,7 @@ text data
218224
{
219225
"type": "event",
220226
"event": "<event_name>",
227+
"ackId": 1,
221228
"dataType" : "json",
222229
"data": {
223230
"hello": "world"
@@ -255,6 +262,7 @@ ce-eventName: <event_name>
255262
{
256263
"type": "event",
257264
"event": "<event_name>",
265+
"ackId": 1,
258266
"dataType" : "binary",
259267
"data": "base64_binary",
260268
}
@@ -302,7 +310,7 @@ Format:
302310
"ackId": 1, // The ack id for the request to ack
303311
"success": false, // true or false
304312
"error": {
305-
"name": "NotFound|Forbidden|Timeout|InternalServerError",
313+
"name": "Forbidden|InternalServerError|Duplicate",
306314
"message": "<error_detail>"
307315
}
308316
}

articles/azure-web-pubsub/reference-protobuf-webpubsub-subprotocol.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,24 @@ message UpstreamMessage {
6464
6565
message SendToGroupMessage {
6666
string group = 1;
67-
optional int32 ack_id = 2;
67+
optional uint64 ack_id = 2;
6868
MessageData data = 3;
6969
}
7070
7171
message EventMessage {
7272
string event = 1;
7373
MessageData data = 2;
74+
optional uint64 ack_id = 3;
7475
}
7576
7677
message JoinGroupMessage {
7778
string group = 1;
78-
optional int32 ack_id = 2;
79+
optional uint64 ack_id = 2;
7980
}
8081
8182
message LeaveGroupMessage {
8283
string group = 1;
83-
optional int32 ack_id = 2;
84+
optional uint64 ack_id = 2;
8485
}
8586
}
8687
@@ -99,21 +100,21 @@ Format:
99100

100101
Set `join_group_message.group` to the group name.
101102

102-
* `ackId` is optional. It's an incremental integer for this command message. If you specify `ackId`, the service sends an [ack response message](#ack-response) back to the client when the command is executed.
103+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
103104

104105
### Leave groups
105106

106107
Format:
107108

108109
Set `leave_group_message.group` to the group name.
109110

110-
* `ackId` is optional. It's an incremental integer for this command message. If you specify `ackId`, the service sends an [ack response message](#ack-response) back to the client when the command is executed.
111+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
111112

112113
### Publish messages
113114

114115
Format:
115116

116-
* `ackId` is optional. It's an incremental integer for this command message. If you specify `ackId`, the service sends an [ack response message](#ack-response) back to the client when the command is executed.
117+
* `ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at [AckId and Ack Response](./concept-client-protocols.md#ackid-and-ack-response)
117118

118119
There's an implicit `dataType`, which can be `protobuf`, `text`, or `binary`, depending on the `data` in `MessageData` you set. The receiver clients can use `dataType` to handle the content correctly.
119120

@@ -342,7 +343,7 @@ message DownstreamMessage {
342343
}
343344
344345
message AckMessage {
345-
int32 ack_id = 1;
346+
uint64 ack_id = 1;
346347
bool success = 2;
347348
optional ErrorMessage error = 3;
348349

0 commit comments

Comments
 (0)