Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for Web PubSub GA #21659

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions sdk/webpubsub/azure-messaging-webpubsubservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,39 @@ When the client is connected, it can send messages to the upstream application,

## Examples

### Broadcast messages
### Broadcast messages in JSON format

```python
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
>>> from azure.identity import DefaultAzureCredential
>>> from azure.core.exceptions import HttpResponseError

>>> service = WebPubSubServiceClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
>>> with open('file.json', 'r') as f:
try:
service.send_to_all('ahub', content=f)
except HttpResponseError as e:
print('service responds error: {}'.format(e.response.json()))
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
>>> service.send_to_all('hub1', message = {
'from': 'user1',
'data': 'Hello world'
})
```

The WebSocket client will receive JSON serialized text: `{"from": "user1", "data": "Hello world"}`.

### Broadcast messages in plain-text format

```python
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
>>> service.send_to_all('hub1', message = 'Hello world', content_type='text/plain')
```

The WebSocket client will receive text: `Hello world`.

### Broadcast messages in binary format

```python
>>> import io
>>> from azure.messaging.webpubsubservice import WebPubSubServiceClient
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>')
>>> service.send_to_all('hub1', message=io.StringIO('Hello World'), content_type='application/octet-stream')
```
The WebSocket client will receive binary text: `b'Hello world'`.

## Troubleshooting

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

## Next steps

Check [more samples here][awps_samples].
Check [more samples here][samples].

## Contributing

Expand Down Expand Up @@ -178,4 +196,4 @@ additional questions or comments.
[azure_portal]: https://docs.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
[azure-key-credential]: https://aka.ms/azsdk-python-core-azurekeycredential
[aad_doc]: https://aka.ms/awps/aad
[awps_samples]: https://github.com/Azure/azure-webpubsub/tree/main/samples/python
[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/webpubsub/azure-messaging-webpubsubservice/samples
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
page_type: sample
languages:
- python
products:
- azure
- azure-messaging-webpubsubservice
urlFragment: azure-messaging-webpubsubservice-samples
---

# Azure Web PubSub service client library for Python Samples

These are code samples that show common scenario operations with the Azure Storage Blob client library.
The async versions of the samples (the python sample files appended with `_async`) show asynchronous operations,
and require Python 3.5 or later.

## Prerequisites
* Python 2.7, or 3.5 or later is required to use this package (3.5 or later if using asyncio)
* You need an [Azure subscription][azure_sub], and a [Azure WebPubSub service instance][webpubsubservice_docs] to use this package.

## Setup

1. Install the Azure Web PubSub service client library for Python with [pip](https://pypi.org/project/pip/):

```bash
pip install azure-messaging-webpubsubservice
```

2. Clone or download this sample repository
3. Open the sample folder in Visual Studio Code or your IDE of choice.

## Running the samples

1. Open a terminal window and `cd` to the directory that the samples are saved in.
2. Set the environment variables specified in the sample file you wish to run.
3. Follow the usage described in the file, e.g. `python get_client_access_token.py`

## More samples

Check [more samples here][servicesample].

## Next Steps

Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.


<!-- LINKS -->
[azure_sub]: https://azure.microsoft.com/free/
[webpubsubservice_docs]: https://aka.ms/awps/doc
[servicesample]: https://github.com/Azure/azure-webpubsub/tree/main/samples/python
[apiref]: https://aka.ms/awps/sdk/python
2 changes: 1 addition & 1 deletion sdk/webpubsub/azure-messaging-webpubsubservice/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
license="MIT License",
author="Microsoft Corporation",
author_email="[email protected]",
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/signalr/azure-messaging-webpubsubservice",
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/webpubsub/azure-messaging-webpubsubservice",
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python",
Expand Down