You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/howto-develop-reliable-clients.md
+22-5Lines changed: 22 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,27 @@ ms.date: 12/15/2021
12
12
13
13
Websocket client connections may drop due to intermittent network issue and when connections drop, messages will also be lost. In a pubsub system, publishers are decoupled from subscribers, so publishers hard to detect subscribers' drop or message loss. It's crucial for clients to overcome intermittent network issue and keep the reliability of message delivery. To achieve that, you can create a reliable Websocket client with the help of reliable subprotocols.
14
14
15
+
> [!NOTE]
16
+
> Reliable protocols are still in preview. Some changes are expected in future.
17
+
15
18
## Reliable Protocol
16
19
17
20
Service supports two reliable subprotocols `json.reliable.webpubsub.azure.v1` and `protobuf.reliable.webpubsub.azure.v1`. Clients must follow the protocol, mainly including the part of reconnection, publisher and subscriber to achieve the reliability, or the message delivery may not work as expected or the service may terminate the client as it violates the protocol spec.
18
21
22
+
## Initialization
23
+
24
+
To use reliable subprotocols, you must set subprotocol when constructing Websocket connections. In JavaScript, you can use as following:
25
+
26
+
- Use Json reliable subprotocol
27
+
```js
28
+
var pubsub =newWebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', 'json.reliable.webpubsub.azure.v1');
29
+
```
30
+
31
+
- Use Protobuf reliable subprotocol
32
+
```js
33
+
var pubsub = new WebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', 'protobuf.reliable.webpubsub.azure.v1');
34
+
```
35
+
19
36
## Reconnection
20
37
21
38
Websocket connections relay on TCP, so if the connection doesn't drop, all messages should be lossless and in order. When facing network issue and connections drop, all the status such as group and message info are kept by the service and wait for reconnection to recover. A Websocket connection owns a session in the service and the identifier is `connectionId`. Reconnection is the basis of achieving reliability and must be implemented. When a new connection connects to the service using reliable subprotocols, the connection will receive a `Connected` message contains `connectionId` and `reconnectionToken`.
@@ -65,7 +82,7 @@ A sample ack response:
65
82
66
83
If the service returns ack with `success: true`, the message has been processed by the service and the client can expect the message will be delivered to all subscribers.
67
84
68
-
However, In some cases, Service meets some transient internal error and the message can't be sent to subscriber. In such case, publisher will receive an ack like following and should resend message with the same `ackId`.
85
+
However, In some cases, Service meets some transient internal error and the message can't be sent to subscriber. In such case, publisher will receive an ack like following and should resend message with the same `ackId` if it's necessary based on business logic.
69
86
70
87
```json
71
88
{
@@ -81,7 +98,7 @@ However, In some cases, Service meets some transient internal error and the mess
Service's ack may be dropped because of WebSockets connection dropped. So, publishers should wait for ack with timeout, and resend message with the same message-id after timeout. If the message has actually processed by the service, it will response ack with `Duplicate` and publishers should stop resending this message again.
101
+
Service's ack may be dropped because of WebSockets connection dropped. So, publishers should get notified when Websocket connection drops and resend message with the same `ackId` after reconnection. If the message has actually processed by the service, it will response ack with `Duplicate` and publishers should stop resending this message again.
85
102
86
103
```json
87
104
{
@@ -99,16 +116,16 @@ Service's ack may be dropped because of WebSockets connection dropped. So, publi
99
116
100
117
## Subscriber
101
118
102
-
Clients who receive messages sent from event handlers or publishers are called subscriber in the document. When connections drop by network issues, the service doesn't know how many messages are actually sent to subscribers. So subscribers should tell the service which message has been received. Messages send to subscribers contains `sequenceId` and subscribers must ack the sequence-id with sequence ack message:
119
+
Clients who receive messages sent from event handlers or publishers are called subscriber in the document. When connections drop by network issues, the service doesn't know how many messages are actually sent to subscribers. So subscribers should tell the service which message has been received. Data Messages contains `sequenceId` and subscribers must ack the sequence-id with sequence ack message:
103
120
104
121
A sample sequence ack:
105
122
```json
106
123
{
107
-
"type": "ack",
124
+
"type": "sequenceAck",
108
125
"sequenceId": 1
109
126
}
110
127
```
111
128
112
-
The sequence-id is a uint64 incremental number with-in a connection-id session. And don't expect the number must be consecutive. Subscribers should record the largest sequence-id it ever received and accept all messages with larger sequence-id and drop all messages with smaller or equal sequence-id. The sequence ack supports quick ack, which means if you ack `sequence-id=5`, the service will treat all messages with sequence-id smaller than 5 have already been received by subscribers. Subscribers should ack with the largest sequence-id it recorded, so that the service can skip redelivering messages that subscribers have already received.
129
+
The sequence-id is a uint64 incremental number with-in a connection-id session. Subscribers should record the largest sequence-id it ever received and accept all messages with larger sequence-id and drop all messages with smaller or equal sequence-id. The sequence ack supports selective ack, which means if you ack `sequence-id=5`, the service will treat all messages with sequence-id smaller than 5 have already been received by subscribers. Subscribers should ack with the largest sequence-id it recorded, so that the service can skip redelivering messages that subscribers have already received.
113
130
114
131
All messages are delivered to subscribers in order until the WebSockets connection drops. With sequence-id, the service can have the knowledge about how many messages subscribers have actually received across WebSockets connections with-in a connection-id session. After a WebSockets connection drop, the service will redeliver messages it should deliver but not ack-ed by the subscriber. The service hold messages that are not ack-ed with limit, if messages exceed the limit, the service will close the WebSockets connection and remove the connection-id session. Thus, subscribers should ack the sequence-id as soon as possible.
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/reference-json-reliable-webpubsub-subprotocol.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,9 @@ This document describes the subprotocol `json.reliable.webpubsub.azure.v1`.
14
14
15
15
When the client is using this subprotocol, both outgoing data frame and incoming data frame are expected to be **JSON** payloads.
16
16
17
+
> [!NOTE]
18
+
> Reliable protocols are still in preview. Some changes are expected in future.
19
+
17
20
## Overview
18
21
19
22
Subprotocol `json.reliable.webpubsub.azure.v1` empowers the client to have a high reliable message delivery experience under network issues and do a publish-subscribe (PubSub) directly instead of doing a round trip to the upstream server. The WebSocket connection with the `json.reliable.webpubsub.azure.v1` subprotocol is called a Reliable PubSub WebSocket client.
@@ -37,7 +40,7 @@ Format:
37
40
38
41
```json
39
42
{
40
-
"type": "ack",
43
+
"type": "sequenceAck",
41
44
"sequenceId": "<sequenceId>",
42
45
}
43
46
```
@@ -48,7 +51,7 @@ Reliable PubSub WebSocket client must send sequence ack message once it received
48
51
49
52
## Responses
50
53
51
-
Messages received by the client can be several types: `ack`, `message`, and `system`. All response messages have `sequenceId` property. Client must send [Sequence Ack](#sequence-ack) to the service once it receives a message.
54
+
Messages received by the client can be several types: `ack`, `message`, and `system`. Messages with type `message` have `sequenceId` property. Client must send [Sequence Ack](#sequence-ack) to the service once it receives a message.
52
55
53
56
### Ack response
54
57
@@ -57,7 +60,6 @@ If the request contains `ackId`, the service will return an ack response for thi
57
60
Format:
58
61
```json
59
62
{
60
-
"sequenceId": 1,
61
63
"type": "ack",
62
64
"ackId": 1, // The ack id for the request to ack
63
65
"success": false, // true or false
@@ -153,7 +155,6 @@ When the connection connects to service.
153
155
154
156
```json
155
157
{
156
-
"sequenceId": 1,
157
158
"type": "system",
158
159
"event": "connected",
159
160
"userId": "user1",
@@ -176,7 +177,6 @@ When the server closes the connection, or when the service declines the client.
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/reference-protobuf-reliable-webpubsub-subprotocol.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,9 @@ This document describes the subprotocol `protobuf.reliable.webpubsub.azure.v1`.
14
14
15
15
When a client is using this subprotocol, both the outgoing and incoming data frames are expected to be protocol buffers (protobuf) payloads.
16
16
17
+
> [!NOTE]
18
+
> Reliable protocols are still in preview. Some changes are expected in future.
19
+
17
20
## Overview
18
21
19
22
Subprotocol `protobuf.reliable.webpubsub.azure.v1` empowers the client to have a high reliable message delivery experience under network issues and do a publish-subscribe (PubSub) directly instead of doing a round trip to the upstream server. The WebSocket connection with the `protobuf.reliable.webpubsub.azure.v1` subprotocol is called a Reliable PubSub WebSocket client.
@@ -53,6 +56,7 @@ message UpstreamMessage {
53
56
string group = 1;
54
57
optional uint64 ack_id = 2;
55
58
MessageData data = 3;
59
+
optional bool no_echo = 4;
56
60
}
57
61
58
62
message EventMessage {
@@ -109,7 +113,6 @@ message DownstreamMessage {
109
113
uint64 ack_id = 1;
110
114
bool success = 2;
111
115
optional ErrorMessage error = 3;
112
-
uint64 sequence_id = 4;
113
116
114
117
message ErrorMessage {
115
118
string name = 1;
@@ -134,18 +137,16 @@ message DownstreamMessage {
134
137
string connection_id = 1;
135
138
string user_id = 2;
136
139
string reconnection_token = 3;
137
-
uint64 sequence_id = 4;
138
140
}
139
141
140
142
message DisconnectedMessage {
141
143
string reason = 2;
142
-
uint64 sequence_id = 3;
143
144
}
144
145
}
145
146
}
146
147
```
147
148
148
-
Messages received by the client can be in any of three types: `ack`, `message`, or `system`. All response messages have`sequence_id` property. Client must send [Sequence Ack](#sequence-ack) to the service once it receives a message.
149
+
`AckMessage` has`sequence_id` property. Client must send [Sequence Ack](#sequence-ack) to the service once it receives a message.
0 commit comments