Skip to content

Commit 8443971

Browse files
authored
Merge pull request #230180 from cebundy/wps-fix-msgs-tutorial2
[Web-PubSub]: Change code labels and replace variable with placeholders
2 parents 15f32d1 + 5a45a8b commit 8443971

File tree

5 files changed

+66
-52
lines changed

5 files changed

+66
-52
lines changed

articles/azure-web-pubsub/includes/cli-awps-connstr.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ ms.date: 08/06/2021
66
ms.author: lianwei
77
---
88

9-
> [!Important]
9+
> [!IMPORTANT]
1010
> A connection string includes the authorization information required for your application to access Azure Web PubSub service. The access key inside the connection string is similar to a root password for your service. In production environments, always be careful to protect your access keys. Use Azure Key Vault to manage and rotate your keys securely. Avoid distributing access keys to other users, hard-coding them, or saving them anywhere in plain text that is accessible to others. Rotate your keys if you believe they may have been compromised.
1111
12-
Use the Azure CLI [az webpubsub key](/cli/azure/webpubsub#az-webpubsub-key) command to get the **ConnectionString** of the service.
12+
Use the Azure CLI [az webpubsub key](/cli/azure/webpubsub#az-webpubsub-key) command to get the **ConnectionString** of the service. Replace the `<your-unique-resource-name>` placeholder with the name of your Azure Web PubSub instance.
1313

14-
```azurecli-interactive
15-
$connection-string=(az webpubsub key show --name "<your-unique-resource-name>" --resource-group "myResourceGroup" --query primaryConnectionString)
14+
```azurecli
15+
az webpubsub key show --resource-group myResourceGroup --name <your-unique-resource-name> --query primaryConnectionString --output tsv
1616
```
17+
18+
Copy the connection string to use later.

articles/azure-web-pubsub/includes/cli-awps-creation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Use the Azure CLI [az webpubsub create](/cli/azure/webpubsub#az-webpubsub-create
1717
> [!Important]
1818
> Each Web PubSub resource must have a unique name. Replace &lt;your-unique-resource-name&gt; with the name of your Web PubSub in the following examples.
1919
20-
```azurecli-interactive
20+
```azurecli
2121
az webpubsub create --name "<your-unique-resource-name>" --resource-group "myResourceGroup" --location "EastUS" --sku Free_F1
2222
```
2323

articles/azure-web-pubsub/includes/cli-awps-setup.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,25 @@ ms.custom: devx-track-azurecli
99

1010
## Azure CLI setup for local development
1111

12-
Follow these steps to set up the Azure CLI and your project environment.
12+
Follow these steps to set up Azure CLI and your project environment.
13+
14+
1. Open a command shell.
1315

1416
1. Upgrade to the latest version of the Azure CLI.
1517

16-
```bash
18+
```azurecli
1719
az upgrade
1820
```
1921
2022
1. Install the Azure CLI extension for Web PubSub.
2123
22-
```bash
24+
```azurecli
2325
az extension add --name webpubsub
2426
```
2527
26-
1. Sign in to the Azure CLI. Following the prompts, enter your Azure credentials.
28+
1. Sign in to Azure CLI. Following the prompts, enter your Azure credentials.
2729
28-
```bash
30+
```azurecli
2931
az login
3032
```
3133
32-
1. Create a resource group.
33-
34-
```bash
35-
az group create --name myResourceGroup --location eastus
36-
```

articles/azure-web-pubsub/includes/cli-rg-creation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ms.date: 08/06/2021
66
ms.author: lianwei
77
---
88

9-
A resource group is a logical container into which Azure resources are deployed and managed. Use the [az group create](/cli/azure/group#az-group-create) command to create a resource group named *myResourceGroup* in the *eastus* location.
9+
A resource group is a logical container into which Azure resources are deployed and managed. Use the [az group create](/cli/azure/group#az-group-create) command to create a resource group named `myResourceGroup` in the `eastus` location.
1010

11-
```azurecli-interactive
12-
az group create --name "myResourceGroup" -l "EastUS"
11+
```azurecli
12+
az group create --name myResourceGroup --location EastUS
1313
```

articles/azure-web-pubsub/tutorial-pub-sub-messages.md

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: vicancy
55
ms.author: lianwei
66
ms.service: azure-web-pubsub
77
ms.topic: tutorial
8-
ms.date: 01/17/2023
8+
ms.date: 03/09/2023
99
---
1010

1111
# Tutorial: Publish and subscribe messages using WebSocket API and Azure Web PubSub service SDK
@@ -22,6 +22,8 @@ In this tutorial, you learn how to:
2222
2323
[!INCLUDE [azure-web-pubsub-tutorial-prerequisites](includes/cli-awps-prerequisites.md)]
2424

25+
You can use the Windows cmd.exe command shell instead of a Bash shell to run the commands in this tutorial.
26+
2527
If creating the project on a local machine, you'll need to install the dependencies for the language you're using:
2628

2729
# [C#](#tab/csharp)
@@ -43,7 +45,7 @@ If creating the project on a local machine, you'll need to install the dependenc
4345

4446
---
4547

46-
## Setup
48+
## Prepare your environment
4749

4850
# [Local Azure CLI](#tab/LocalBash)
4951

@@ -55,7 +57,7 @@ If creating the project on a local machine, you'll need to install the dependenc
5557

5658
---
5759

58-
### Create a resource group
60+
## Create a resource group
5961

6062
[!INCLUDE [Create a resource group](includes/cli-rg-creation.md)]
6163

@@ -66,7 +68,20 @@ If creating the project on a local machine, you'll need to install the dependenc
6668

6769
### Create a Web PubSub instance
6870

69-
[!INCLUDE [Create a Web PubSub instance](includes/cli-awps-creation.md)]
71+
Use the Azure CLI [az webpubsub create](/cli/azure/webpubsub#az-webpubsub-create) command to create a Web PubSub in the resource group you've created. The following command creates a _Free_ Web PubSub resource under resource group `myResourceGroup` in `EastUS`:
72+
73+
Each Web PubSub resource must have a unique name. Replace &lt;your-unique-resource-name&gt; with the name of your Web PubSub instance in the following command.
74+
75+
```azurecli
76+
az webpubsub create --resource-group myResourceGroup --name <your-unique-resource-name> --location EastUS --sku Free_F1
77+
```
78+
79+
The output of this command shows properties of the newly created resource. Take note of the two properties listed below:
80+
81+
* **name**: The Web PubSub name you provided in the `--name` parameter above.
82+
* **hostName**: In the example, the host name is `<your-unique-resource-name>.webpubsub.azure.com/`.
83+
84+
At this point, your Azure account is the only one authorized to perform any operations on this new resource.
7085

7186
### Get the connection string
7287

@@ -80,7 +95,7 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
8095

8196
1. First, create a project directory named `subscriber` for this project and install required dependencies:
8297

83-
* The package [Websocket.Client](https://github.com/Marfusios/websocket-client) is a third-party package supporting WebSocket connection. You can use any API/library that supports WebSocket to do so.
98+
* The package [Websocket.Client](https://github.com/Marfusios/websocket-client) is a third-party package supporting WebSocket connections. You can use any API/library that supports WebSocket.
8499
* The SDK package `Azure.Messaging.WebPubSub` helps to generate the JWT token.
85100

86101
```bash
@@ -140,10 +155,10 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
140155
141156
After the connection is established, your client receives messages through the WebSocket connection. The client uses `client.MessageReceived.Subscribe(msg => ...));` to listen for incoming messages.
142157
143-
1. Run the following command:
158+
1. To start the subscriber, run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier:
144159
145160
```bash
146-
dotnet run $connection_string "myHub1"
161+
dotnet run <Web-PubSub-connection-string> "myHub1"
147162
```
148163
149164
# [JavaScript](#tab/javascript)
@@ -183,11 +198,11 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
183198
184199
After the connection is established, your client receives messages through the WebSocket connection. The client uses `client.MessageReceived.Subscribe(msg => ...));` to listen for incoming messages.
185200
186-
1. Run the following command:
201+
1. Run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier. If you are using Windows command shell, you can use `set` instead of `export`.
187202
188203
```bash
189-
export WebPubSubConnectionString=$connection_string
190-
node subscribe
204+
export WebPubSubConnectionString=<Web-PubSub-connection-string>
205+
node subscribe.js
191206
```
192207
193208
# [Python](#tab/python)
@@ -248,10 +263,10 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
248263
249264
After the connection is established, your client will receive messages through the WebSocket connection. Use `await ws.recv()` to listen for incoming messages.
250265
251-
1. Run the following command:
266+
1. Run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier:
252267
253268
```bash
254-
python subscribe.py $connection_string "myHub1"
269+
python subscribe.py <Web-PubSub-connection-string> "myHub1"
255270
```
256271
257272
# [Java](#tab/java)
@@ -265,7 +280,7 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
265280
266281
1. Inside the `pubsub` directory, use Maven to create a new console app called `webpubsub-quickstart-subscriber`, then go to the *webpubsub-quickstart-subscriber* directory:
267282
268-
```console
283+
```bash
269284
mvn archetype:generate --define interactiveMode=n --define groupId=com.webpubsub.quickstart --define artifactId=webpubsub-quickstart-subscriber --define archetypeArtifactId=maven-archetype-quickstart --define archetypeVersion=1.4
270285
cd webpubsub-quickstart-subscriber
271286
```
@@ -363,10 +378,10 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
363378
364379
After connection is established, your client will receive messages through the WebSocket connection. Use `onMessage(String message)` to listen for incoming messages.
365380
366-
1. Navigate to the *webpubsub-quickstart-subscriber* directory and run the app with following command:
381+
1. To start the subscriber app, go to the *webpubsub-quickstart-subscriber* directory and run the following command. Replace `<Web-PubSub-connection-string>` with the connection string you copied earlier.
367382
368-
```console
369-
mvn compile & mvn package & mvn exec:java -Dexec.mainClass="com.webpubsub.quickstart.App" -Dexec.cleanupDaemonThreads=false -Dexec.args="$connection_string 'myHub1'"
383+
```bash
384+
mvn compile & mvn package & mvn exec:java -Dexec.mainClass="com.webpubsub.quickstart.App" -Dexec.cleanupDaemonThreads=false -Dexec.args="<Web-PubSub-connection-string> 'myHub1'"
370385
```
371386
372387
---
@@ -418,15 +433,15 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
418433
419434
The `SendToAllAsync()` call simply sends a message to all connected clients in the hub.
420435
421-
1. Send a message by running the command:
436+
1. Send a message by running the following command. Replace `<Web-PubSub-connection-string>` with the connection string you copied earlier.
422437
423438
```bash
424-
dotnet run $connection_string "myHub1" "Hello World"
439+
dotnet run <Web-PubSub-connection-string> "myHub1" "Hello World"
425440
```
426441
427-
1. Check the command shell of the previous subscriber to see that it received the message:
442+
1. Check the command shell of the subscriber to see that it received the message:
428443
429-
```text
444+
```console
430445
Message received: Hello World
431446
```
432447
@@ -456,16 +471,16 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
456471
457472
The `service.sendToAll()` call simply sends a message to all connected clients in a hub.
458473
459-
1. Send a message by running the command:
474+
1. To send a message, run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier. If you are using Windows command shell, you can use `set` instead of `export`.
460475
461476
```bash
462-
export WebPubSubConnectionString=$connection_string
477+
export WebPubSubConnectionString=<Web-PubSub-connection-string>
463478
node publish "Hello World"
464479
```
465480
466-
1. You can see that the previous subscriber received the message:
481+
1. You can see that the subscriber received the message:
467482
468-
```text
483+
```console
469484
Message received: Hello World
470485
```
471486
@@ -508,23 +523,23 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
508523
509524
The `send_to_all()` send the message to all connected clients in a hub.
510525
511-
1. Run the following command:
526+
1. To send a message, run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier.
512527
513528
```bash
514-
python publish.py $connection_string "myHub1" "Hello World"
529+
python publish.py <Web-PubSub-connection-string> "myHub1" "Hello World"
515530
```
516531
517532
1. Check the previous command shell to that the subscriber received the message:
518533
519-
```text
534+
```console
520535
Received message: Hello World
521536
```
522537
523538
# [Java](#tab/java)
524539
525540
1. Go to the `pubsub` directory. Use Maven to create a publisher console app `webpubsub-quickstart-publisher` and go to the *webpubsub-quickstart-publisher* directory:
526541
527-
```console
542+
```bash
528543
mvn archetype:generate --define interactiveMode=n --define groupId=com.webpubsub.quickstart --define artifactId=webpubsub-quickstart-publisher --define archetypeArtifactId=maven-archetype-quickstart --define archetypeVersion=1.4
529544
cd webpubsub-quickstart-publisher
530545
```
@@ -573,15 +588,15 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
573588
574589
The `sendToAll()` call sends a message to all connected clients in a hub.
575590
576-
1. Go to the *webpubsub-quickstart-publisher* directory and run the project using the following command:
591+
1. To send a message, go to the *webpubsub-quickstart-publisher* directory and run the project using the following command. Replace the `<Web-PubSub-connection-string>` with the connection string you copied earlier.
577592
578-
```console
579-
mvn compile & mvn package & mvn exec:java -Dexec.mainClass="com.webpubsub.quickstart.App" -Dexec.cleanupDaemonThreads=false -Dexec.args="$connection_string 'myHub1' 'Hello World'"
593+
```bash
594+
mvn compile & mvn package & mvn exec:java -Dexec.mainClass="com.webpubsub.quickstart.App" -Dexec.cleanupDaemonThreads=false -Dexec.args="<Web-PubSub-connection-string> 'myHub1' 'Hello World'"
580595
```
581596
582-
1. You can see that the previous subscriber received the message:
597+
1. You can see that the subscriber received the message:
583598
584-
```text
599+
```console
585600
Message received: Hello World
586601
```
587602
@@ -608,7 +623,7 @@ az group delete --name <CloudShellResourceGroup> --yes
608623
609624
## Next steps
610625
611-
This tutorial provides you a basic idea of how to connect to the Web PubSub service and publish messages to the connected clients.
626+
This tutorial provides you with a basic idea of how to connect to the Web PubSub service and publish messages to the connected clients.
612627
613628
Check other tutorials to dive further into how to use the service.
614629

0 commit comments

Comments
 (0)