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
3. The `stopped` event is triggered when the client is disconnected **and** the client stops trying to reconnect. This usually happens after the `client.stop()`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.start()`in the stopped event.
98
104
99
105
```python
100
-
client.on("stopped", lambda : print("Client has stopped"))
106
+
from azure.messaging.webpubsubclient.models import CallbackType
107
+
108
+
client.subscribe(CallbackType.STOPPED, lambda : print("Client has stopped"))
101
109
```
102
110
103
111
### A client consumes messages from the application server or joined groups
104
112
105
113
A client can add callbacks to consume messages from your application server or groups. Note, for`group-message` event the client can _only_ receive group messages that it has joined.
106
114
107
115
```python
116
+
from azure.messaging.webpubsubclient.models import CallbackType
117
+
108
118
# Registers a listener for the "server-message". The callback is invoked when your application server sends message to the connectionID, to or broadcast to all connections.
# Registers a listener for the "group-message". The callback is invoked when the client receives a message from the groups it has joined.
112
-
client.on("group-message", lambdae: print(f"Received message from {e.group}: {e.data}"))
122
+
client.subscribe(CallbackType.GROUP_MESSAGE, lambdae: print(f"Received message from {e.group}: {e.data}"))
113
123
```
114
124
---
115
125
### Handle rejoin failure
@@ -120,11 +130,13 @@ However, you should be aware of `auto_rejoin_groups`'s limitations.
120
130
-"rejoin group" operations may fail due to various reasons, for example, the client doesn't have permission to join the groups. In such cases, you need to add a callback to handle this failure.
121
131
122
132
```python
133
+
from azure.messaging.webpubsubclient.models import CallbackType
134
+
123
135
# By default auto_rejoin_groups=True. You can disable it by setting to False.
0 commit comments