Skip to content

Commit a4a0ad1

Browse files
msyycannatisch
andauthored
[Webpubsub] async API (#34764)
* init * basic function and perf * update * async test * black * optimize retry logic * update for sample * set policy for async test in windows * remove async lock * fix cspell * fix mypy * fix pylint * update dependency * aiohttp>=3.8.0 in setup.py * fix for Linux * optimize for sync api * fix sample * optiize for async api * review * update test * update dependency * update * fix recovery and reconnect logic * update test case * update * optimize * async test for open client error * typing fix * typing fix * typing fix * review for on_error * stress test * fix cspell * fix cspell * update logging for stress * rename stress readme * update * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_util.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py Co-authored-by: Anna Tisch <[email protected]> * Update sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/aio/_client.py Co-authored-by: Anna Tisch <[email protected]> * review * review * review * update changelog * update test case name * fix test * optimize close logic * mypy fix * optimize client.close logic for async api * udpate changelog * expose is_connected * review * remove nested function * set all created thread as daemon * Update CHANGELOG.md --------- Co-authored-by: Anna Tisch <[email protected]>
1 parent f892ccf commit a4a0ad1

29 files changed

+2522
-323
lines changed

.vscode/cspell.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,17 @@
17121712
]
17131713
},
17141714
{
1715-
"filename": "sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/_client.py",
1715+
"filename": "sdk/webpubsub/azure-messaging-webpubsubclient/azure/messaging/webpubsubclient/**/_client.py",
17161716
"words": [
17171717
"awps"
17181718
]
17191719
},
1720+
{
1721+
"filename": "sdk/webpubsub/azure-messaging-webpubsubclient/stress/*.py",
1722+
"words": [
1723+
"psutil"
1724+
]
1725+
},
17201726
{
17211727
"filename": "sdk/contentsafety/azure-ai-contentsafety/azure/ai/contentsafety/*.py",
17221728
"words": [

sdk/webpubsub/azure-messaging-webpubsubclient/CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# Release History
22

3-
## 1.0.1 (Unreleased)
3+
## 1.1.0 (2024-04-24)
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
7+
- Add Async API with same name of Sync API
8+
- Add api `is_connected`
109

1110
### Other Changes
1211

12+
- Change default reconnect times to unlimited
13+
- Optimize reconnect/recover logic
14+
- Optimize error message hint when failed to open client
15+
- Optimize typing annotations
16+
- Optimize close logic for Sync API.
17+
1318
## 1.0.0 (2024-01-31)
1419

1520
### Features Added

sdk/webpubsub/azure-messaging-webpubsubclient/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Note that a client can only receive messages from groups that it has joined and
6060

6161
# Registers a listener for the event 'group-message' early before joining a group to not miss messages
6262
group_name = "group1";
63-
client.subscribe("group-message", lambda e: print(f"Received message: {e.data}"));
63+
client.subscribe(CallbackType.GROUP_MESSAGE, lambda e: print(f"Received message: {e.data}"));
6464

6565
# A client needs to join the group it wishes to receive messages from
6666
client.join_group(groupName);
@@ -72,7 +72,7 @@ client.join_group(groupName);
7272
# ...continues the code snippet from above
7373

7474
# Send a message to a joined group
75-
client.send_to_group(group_name, "hello world", "text");
75+
client.send_to_group(group_name, "hello world", WebPubSubDataType.TEXT);
7676

7777
# In the Console tab of your developer tools found in your browser, you should see the message printed there.
7878
```
@@ -84,19 +84,19 @@ client.send_to_group(group_name, "hello world", "text");
8484
1. When a client is successfully connected to your Web PubSub resource, the `connected` event is triggered.
8585

8686
```python
87-
client.subscribe("connected", lambda e: print(f"Connection {e.connection_id} is connected"))
87+
client.subscribe(CallbackType.CONNECTED, lambda e: print(f"Connection {e.connection_id} is connected"))
8888
```
8989

9090
2. When a client is disconnected and fails to recover the connection, the `disconnected` event is triggered.
9191

9292
```python
93-
client.subscribe("disconnected", lambda e: print(f"Connection disconnected: {e.message}"))
93+
client.subscribe(CallbackType.DISCONNECTED, lambda e: print(f"Connection disconnected: {e.message}"))
9494
```
9595

9696
3. The `stopped` event will be triggered when the client is disconnected *and* the client stops trying to reconnect. This usually happens after the `client.close()` is called, or `auto_reconnect` is disabled or a specified limit to trying to reconnect has reached. If you want to restart the client, you can call `client.open()` in the stopped event.
9797

9898
```python
99-
client.subscribe("stopped", lambda : print("Client has stopped"))
99+
client.subscribe(CallbackType.STOPPED, lambda : print("Client has stopped"))
100100
```
101101

102102
---
@@ -106,10 +106,10 @@ A client can add callbacks to consume messages from your application server or g
106106

107107
```python
108108
# Registers a listener for the "server-message". The callback will be invoked when your application server sends message to the connectionID, to or broadcast to all connections.
109-
client.subscribe("server-message", lambda e: print(f"Received message {e.data}"))
109+
client.subscribe(CallbackType.SERVER_MESSAGE, lambda e: print(f"Received message {e.data}"))
110110

111111
# Registers a listener for the "group-message". The callback will be invoked when the client receives a message from the groups it has joined.
112-
client.subscribe("group-message", lambda e: print(f"Received message from {e.group}: {e.data}"))
112+
client.subscribe(CallbackType.GROUP_MESSAGE, lambda e: print(f"Received message from {e.group}: {e.data}"))
113113
```
114114

115115
---
@@ -125,7 +125,7 @@ However, you should be aware of `auto_rejoin_groups`'s limitations.
125125
client = WebPubSubClient("<client-access-url>", auto_rejoin_groups=True);
126126

127127
# Registers a listener to handle "rejoin-group-failed" event
128-
client.subscribe("rejoin-group-failed", lambda e: print(f"Rejoin group {e.group} failed: {e.error}"))
128+
client.subscribe(CallbackType.REJOIN_GROUP_FAILED, lambda e: print(f"Rejoin group {e.group} failed: {e.error}"))
129129
```
130130

131131
---

0 commit comments

Comments
 (0)