Skip to content

Commit 13f2d0f

Browse files
authored
Update docs for Web PubSub GA (Azure#21659)
* Update setup.py * Update README.md * Create Readme.md
1 parent 1508fb9 commit 13f2d0f

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,39 @@ When the client is connected, it can send messages to the upstream application,
8383

8484
## Examples
8585

86-
### Broadcast messages
86+
### Broadcast messages in JSON format
8787

8888
```python
8989
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
90-
>>> from azure.identity import DefaultAzureCredential
91-
>>> from azure.core.exceptions import HttpResponseError
9290

93-
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
94-
>>> with open('file.json', 'r') as f:
95-
try:
96-
service.send_to_all('ahub', content=f)
97-
except HttpResponseError as e:
98-
print('service responds error: {}'.format(e.response.json()))
91+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
92+
>>> service.send_to_all('hub1', message = {
93+
'from': 'user1',
94+
'data': 'Hello world'
95+
})
96+
```
97+
98+
The WebSocket client will receive JSON serialized text: `{"from": "user1", "data": "Hello world"}`.
99+
100+
### Broadcast messages in plain-text format
99101

102+
```python
103+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
104+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
105+
>>> service.send_to_all('hub1', message = 'Hello world', content_type='text/plain')
106+
```
107+
108+
The WebSocket client will receive text: `Hello world`.
109+
110+
### Broadcast messages in binary format
111+
112+
```python
113+
>>> import io
114+
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
115+
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
116+
>>> service.send_to_all('hub1', message=io.StringIO('Hello World'), content_type='application/octet-stream')
100117
```
118+
The WebSocket client will receive binary text: `b'Hello world'`.
101119

102120
## Troubleshooting
103121

@@ -138,7 +156,7 @@ Http request and response details are printed to stdout with this logging config
138156

139157
## Next steps
140158

141-
Check [more samples here][awps_samples].
159+
Check [more samples here][samples].
142160

143161
## Contributing
144162

@@ -178,4 +196,4 @@ additional questions or comments.
178196
[azure_portal]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
179197
[azure-key-credential]: https://aka.ms/azsdk-python-core-azurekeycredential
180198
[aad_doc]: https://aka.ms/awps/aad
181-
[awps_samples]: https://github.com/Azure/azure-webpubsub/tree/main/samples/python
199+
[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/webpubsub/azure-messaging-webpubsubservice/samples
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- python
5+
products:
6+
- azure
7+
- azure-messaging-webpubsubservice
8+
urlFragment: azure-messaging-webpubsubservice-samples
9+
---
10+
11+
# Azure Web PubSub service client library for Python Samples
12+
13+
These are code samples that show common scenario operations with the Azure Storage Blob client library.
14+
The async versions of the samples (the python sample files appended with `_async`) show asynchronous operations,
15+
and require Python 3.5 or later.
16+
17+
## Prerequisites
18+
* Python 2.7, or 3.5 or later is required to use this package (3.5 or later if using asyncio)
19+
* You need an [Azure subscription][azure_sub], and a [Azure WebPubSub service instance][webpubsubservice_docs] to use this package.
20+
21+
## Setup
22+
23+
1. Install the Azure Web PubSub service client library for Python with [pip](https://pypi.org/project/pip/):
24+
25+
```bash
26+
pip install azure-messaging-webpubsubservice
27+
```
28+
29+
2. Clone or download this sample repository
30+
3. Open the sample folder in Visual Studio Code or your IDE of choice.
31+
32+
## Running the samples
33+
34+
1. Open a terminal window and `cd` to the directory that the samples are saved in.
35+
2. Set the environment variables specified in the sample file you wish to run.
36+
3. Follow the usage described in the file, e.g. `python get_client_access_token.py`
37+
38+
## More samples
39+
40+
Check [more samples here][servicesample].
41+
42+
## Next Steps
43+
44+
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
45+
46+
47+
<!-- LINKS -->
48+
[azure_sub]: https://azure.microsoft.com/free/
49+
[webpubsubservice_docs]: https://aka.ms/awps/doc
50+
[servicesample]: https://github.com/Azure/azure-webpubsub/tree/main/samples/python
51+
[apiref]: https://aka.ms/awps/sdk/python

sdk/webpubsub/azure-messaging-webpubsubservice/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
license="MIT License",
4040
author="Microsoft Corporation",
4141
author_email="[email protected]",
42-
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/signalr/azure-messaging-webpubsubservice",
42+
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/webpubsub/azure-messaging-webpubsubservice",
4343
classifiers=[
4444
"Development Status :: 4 - Beta",
4545
"Programming Language :: Python",

0 commit comments

Comments
 (0)