Skip to content

Commit 2199094

Browse files
authored
[WebPubSub] Use consistent service description and introduction across all languages (#21544)
* Update Web PubSub readme 1. To keep the service description consistent across different languages 2. update some links * Update README.md
1 parent 10a1322 commit 2199094

File tree

1 file changed

+57
-83
lines changed
  • sdk/webpubsub/azure-messaging-webpubsubservice

1 file changed

+57
-83
lines changed
Lines changed: 57 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,85 @@
1-
# Azure WebPubSubService client library for Python
1+
# Azure Web PubSub service client library for Python
22

3-
[Azure Web PubSub Service](https://aka.ms/awps/doc) is a service that enables you to build real-time messaging web applications using WebSockets and the publish-subscribe pattern. Any platform supporting WebSocket APIs can connect to the service easily, e.g. web pages, mobile applications, edge devices, etc. The service manages the WebSocket connections for you and allows up to 100K concurrent connections. It provides powerful APIs for you to manage these clients and deliver real-time messages.
3+
[Azure Web PubSub Service](https://aka.ms/awps/doc) is an Azure-managed service that helps developers easily build web applications with real-time features and publish-subscribe pattern. Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests can also use Azure Web PubSub service.
44

5-
Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients, can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests, can also use Azure Web PubSub service.
5+
You can use this library in your app server side to manage the WebSocket client connections, as shown in below diagram:
66

7-
We list some examples that are good to use Azure Web PubSub service:
7+
![overflow](https://user-images.githubusercontent.com/668244/140014067-25a00959-04dc-47e8-ac25-6957bd0a71ce.png)
88

9-
- **High frequency data updates:** gaming, voting, polling, auction.
10-
- **Live dashboards and monitoring:** company dashboard, financial market data, instant sales update, multi-player game leader board, and IoT monitoring.
11-
- **Cross-platform live chat:** live chat room, chat bot, on-line customer support, real-time shopping assistant, messenger, in-game chat, and so on.
12-
- **Real-time location on map:** logistic tracking, delivery status tracking, transportation status updates, GPS apps.
13-
- **Real-time targeted ads:** personalized real-time push ads and offers, interactive ads.
14-
- **Collaborative apps:** coauthoring, whiteboard apps and team meeting software.
15-
- **Push instant notifications:** social network, email, game, travel alert.
16-
- **Real-time broadcasting:** live audio/video broadcasting, live captioning, translating, events/news broadcasting.
17-
- **IoT and connected devices:** real-time IoT metrics, remote control, real-time status, and location tracking.
18-
- **Automation:** real-time trigger from upstream events.
19-
20-
Use the client library to:
21-
22-
- Send messages to hubs and groups.
9+
Use this library to:
10+
- Send messages to hubs and groups.
2311
- Send messages to particular users and connections.
2412
- Organize users and connections into groups.
2513
- Close connections
26-
- Grant/revoke/check permissions for an existing connection
14+
- Grant, revoke, and check permissions for an existing connection
2715

28-
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/webpubsub/azure-messaging-webpubsubservice) | [Package (Pypi)][package] | [API reference documentation](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/webpubsub/azure-messaging-webpubsubservice) | [Product documentation][webpubsubservice_docs]
16+
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/webpubsub/azure-messaging-webpubsubservice) | [Package (Pypi)][package] | [API reference documentation](https://aka.ms/awps/sdk/python) | [Product documentation][webpubsubservice_docs]
2917

3018
## Getting started
3119

32-
### Installating the package
33-
34-
```bash
35-
python -m pip install azure-messaging-webpubsubservice
36-
```
37-
38-
#### Prequisites
20+
### Prerequisites
3921

4022
- Python 2.7, or 3.6 or later is required to use this package.
4123
- You need an [Azure subscription][azure_sub], and a [Azure WebPubSub service instance][webpubsubservice_docs] to use this package.
4224
- An existing Azure Web PubSub service instance.
4325

44-
### Authenticating the client
26+
### 1. Install the package
4527

46-
#### 1. Create the client from the service connection string
28+
```bash
29+
python -m pip install azure-messaging-webpubsubservice
30+
```
4731

48-
You can get the [API key][api_key] or [Connection string][connection_string] in the [Azure Portal][azure_portal].
49-
Once you have the value for the API key, you can pass it as a string into an instance of [AzureKeyCredential][azure-key-credential].
50-
Use the key as the credential parameter to authenticate the client:
32+
### 2. Create and authenticate a WebPubSubServiceClient
33+
34+
You can authenticate the `WebPubSubServiceClient` using [connection string][connection_string]:
5135

5236
```python
5337
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
54-
>>> from azure.core.credentials import AzureKeyCredential
5538

56-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=AzureKeyCredential("<api_key>"))
39+
>>> service = WebPubSubServiceClient.from_connection_string(connection_string='<connection_string>')
5740
```
5841

59-
Once you have the value for the connection string, you can pass it as a string into the function `from_connection_string` and it will
60-
authenticate the client:
42+
Or using the service endpoint and the access key:
43+
6144
```python
6245
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
46+
>>> from azure.core.credentials import AzureKeyCredential
6347

64-
>>> client = WebPubSubServiceClient.from_connection_string(connection_string='<connection_string>')
48+
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', credential=AzureKeyCredential("<access_key>"))
6549
```
6650

67-
#### 2. Create with an Azure Active Directory Credential
68-
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
69-
provide an instance of the desired credential type obtained from the
70-
[azure-identity][azure_identity_credentials] library.
51+
Or using [Azure Active Directory][aad_doc]:
52+
1. [pip][pip] install [`azure-identity`][azure_identity_pip]
53+
2. Follow the document to [enable AAD authentication on your Webpubsub resource][aad_doc]
54+
3. Update code to use [DefaultAzureCredential][default_azure_credential]
7155

72-
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip] and
73-
[enable AAD authentication on your Webpubsub resource][enable_aad]
56+
```python
57+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
58+
>>> from azure.identity import DefaultAzureCredential
59+
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
60+
```
7461

75-
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
76-
As an example, [DefaultAzureCredential][default_azure_credential]
77-
can be used to authenticate the client:
62+
## Key concepts
7863

79-
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
80-
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
64+
### Connection
8165

82-
Use the returned token credential to authenticate the client:
66+
A connection, also known as a client or a client connection, represents an individual WebSocket connection connected to the Web PubSub service. When successfully connected, a unique connection ID is assigned to this connection by the Web PubSub service.
8367

84-
```python
85-
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
86-
>>> from azure.identity import DefaultAzureCredential
87-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
88-
```
68+
### Hub
69+
70+
A hub is a logical concept for a set of client connections. Usually you use one hub for one purpose, for example, a chat hub, or a notification hub. When a client connection is created, it connects to a hub, and during its lifetime, it belongs to that hub. Different applications can share one Azure Web PubSub service by using different hub names.
71+
72+
### Group
73+
74+
A group is a subset of connections to the hub. You can add a client connection to a group, or remove the client connection from the group, anytime you want. For example, when a client joins a chat room, or when a client leaves the chat room, this chat room can be considered to be a group. A client can join multiple groups, and a group can contain multiple clients.
75+
76+
### User
77+
78+
Connections to Web PubSub can belong to one user. A user might have multiple connections, for example when a single user is connected across multiple devices or multiple browser tabs.
79+
80+
### Message
81+
82+
When the client is connected, it can send messages to the upstream application, or receive messages from the upstream application, through the WebSocket connection.
8983

9084
## Examples
9185

@@ -96,37 +90,15 @@ Use the returned token credential to authenticate the client:
9690
>>> from azure.identity import DefaultAzureCredential
9791
>>> from azure.core.exceptions import HttpResponseError
9892

99-
>>> client = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
93+
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
10094
>>> with open('file.json', 'r') as f:
10195
try:
102-
client.send_to_all('ahub', content=f, content_type='application/json')
96+
service.send_to_all('ahub', content=f, content_type='application/json')
10397
except HttpResponseError as e:
10498
print('service responds error: {}'.format(e.response.json()))
10599

106100
```
107101

108-
## Key concepts
109-
110-
### Connection
111-
112-
Connections, represented by a connection id, represent an individual websocket connection to the Web PubSub service. Connection id is always unique.
113-
114-
### Hub
115-
116-
Hub is a logical concept for a set of connections. Connections are always connected to a specific hub. Messages that are broadcast to the hub are dispatched to all connections to that hub. Hub can be used for different applications, different applications can share one Azure Web PubSub service by using different hub names.
117-
118-
### Group
119-
120-
Group allow broadcast messages to a subset of connections to the hub. You can add and remove users and connections as needed. A client can join multiple groups, and a group can contain multiple clients.
121-
122-
### User
123-
124-
Connections to Web PubSub can belong to one user. A user might have multiple connections, for example when a single user is connected across multiple devices or multiple browser tabs.
125-
126-
### Message
127-
128-
Using this library, you can send messages to the client connections. A message can either be string text, JSON or binary payload.
129-
130102
## Troubleshooting
131103

132104
### Logging
@@ -151,22 +123,22 @@ logger.addHandler(handler)
151123
endpoint = "<endpoint>"
152124
credential = DefaultAzureCredential()
153125

154-
# This client will log detailed information about its HTTP sessions, at DEBUG level
155-
client = WebPubSubServiceClient(endpoint=endpoint, credential=credential, logging_enable=True)
126+
# This WebPubSubServiceClient will log detailed information about its HTTP sessions, at DEBUG level
127+
service = WebPubSubServiceClient(endpoint=endpoint, credential=credential, logging_enable=True)
156128
```
157129

158130
Similarly, `logging_enable` can enable detailed logging for a single call,
159-
even when it isn't enabled for the client:
131+
even when it isn't enabled for the WebPubSubServiceClient:
160132

161133
```python
162-
result = client.send_to_all(..., logging_enable=True)
134+
result = service.send_to_all(..., logging_enable=True)
163135
```
164136

165137
Http request and response details are printed to stdout with this logging config.
166138

167139
## Next steps
168140

169-
More examples are coming soon...
141+
Check [more samples here][awps_samples].
170142

171143
## Contributing
172144

@@ -205,3 +177,5 @@ additional questions or comments.
205177
[connection_string]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-websocket-connect?tabs=browser#authorization
206178
[azure_portal]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
207179
[azure-key-credential]: https://aka.ms/azsdk-python-core-azurekeycredential
180+
[aad_doc]: https://aka.ms/awps/aad
181+
[awps_samples]: https://github.com/Azure/azure-webpubsub/tree/main/samples/python

0 commit comments

Comments
 (0)