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
Merge pull request #281716 from Akhilesh-microsoft/AWP/tutorial_pub_sub_messages
[AWP: tutorial-pub-sub-messages]: Verified the article for links and freshness, reviewed the content, verified/fixed editorial errors. Article seems good. Updated ms.date
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/tutorial-pub-sub-messages.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,26 +6,26 @@ ms.author: lianwei
6
6
ms.service: azure-web-pubsub
7
7
ms.custom: devx-track-azurecli
8
8
ms.topic: tutorial
9
-
ms.date: 03/09/2023
9
+
ms.date: 09/03/2024
10
10
---
11
11
12
12
# Tutorial: Publish and subscribe messages using WebSocket API and Azure Web PubSub service SDK
13
13
14
-
The Azure Web PubSub service helps you to easily build real-time web messaging applications. In this tutorial, you'll learn how to subscribe to the service using WebSocket API and publish messages using the Web PubSub service SDK.
14
+
The Azure Web PubSub service helps you easily build real-time web messaging applications. In this tutorial, you learn how to subscribe to the service using the WebSocket API and publish messages using the Web PubSub service SDK.
15
15
16
16
In this tutorial, you learn how to:
17
17
18
18
> [!div class="checklist"]
19
19
> * Create a Web PubSub service instance
20
20
> * Generate the full URL to establish the WebSocket connection
21
-
> * Create a Web PubSub subscriber client to receive messages using standard WebSocket protocol
22
-
> * Create a Web PubSub publisher client to publish messages using Web PubSub service SDK
21
+
> * Create a Web PubSub subscriber client to receive messages using the standard WebSocket protocol
22
+
> * Create a Web PubSub publisher client to publish messages using the Web PubSub service SDK
You can use the Windows cmd.exe command shell instead of a Bash shell to run the commands in this tutorial.
27
27
28
-
If creating the project on a local machine, you'll need to install the dependencies for the language you're using:
28
+
If you're creating the project on a local machine, you need to install the dependencies for the language you're using:
29
29
30
30
# [C#](#tab/csharp)
31
31
@@ -69,15 +69,15 @@ If creating the project on a local machine, you'll need to install the dependenc
69
69
70
70
### Create a Web PubSub instance
71
71
72
-
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
+
To create a Web PubSub instance in the resource group you created, use the Azure CLI [az webpubsub create](/cli/azure/webpubsub#az-webpubsub-create) command. The following command creates a _Free_ Web PubSub resource under resource group `myResourceGroup` in `EastUS`:
73
73
74
74
Each Web PubSub resource must have a unique name. Replace <your-unique-resource-name> with the name of your Web PubSub instance in the following command.
1. Replace the code in the `Program.cs` with the following code that will connect to the service:
110
+
1. Replace the code in the `Program.cs` with the following code that connects to the service:
111
111
112
112
```csharp
113
113
using System;
@@ -199,7 +199,7 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
199
199
200
200
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.
201
201
202
-
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`.
202
+
1. Run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier. If you're using Windows command shell, you can use `set` instead of `export`.
@@ -389,7 +389,7 @@ Clients connect to the Azure Web PubSub service through the standard WebSocket p
389
389
390
390
## 2. Publish messages using service SDK
391
391
392
-
Create a publisher using the Azure Web PubSub SDK to publish a message to the connected client. For this project, you'll need to open another command shell.
392
+
Create a publisher using the Azure Web PubSub SDK to publish a message to the connected client. For this project, you need to open another command shell.
393
393
394
394
# [C#](#tab/csharp)
395
395
@@ -440,7 +440,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
440
440
dotnet run <Web-PubSub-connection-string> "myHub1" "Hello World"
441
441
```
442
442
443
-
1. Check the command shell of the subscriber to see that it received the message:
443
+
1. Verify that the subscriber's command shell receives the message:
444
444
445
445
```console
446
446
Message received: Hello World
@@ -458,7 +458,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
458
458
459
459
```
460
460
461
-
1. Use Azure Web PubSub SDK to publish a message to the service. Create a `publish.js` file with the below code:
461
+
1. Use Azure Web PubSub SDK to publish a message to the service. Create a `publish.js` file with the following code:
@@ -472,7 +472,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
472
472
473
473
The `service.sendToAll()` call simply sends a message to all connected clients in a hub.
474
474
475
-
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`.
475
+
1. To send a message, run the following command replacing `<Web-PubSub-connection-string>` with the connection string you copied earlier. If you're using the Windows command shell, you can use `set` instead of `export`.
@@ -501,7 +501,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
501
501
502
502
```
503
503
504
-
1. Use the Azure Web PubSub SDK to publish a message to the service. Create a `publish.py` file with the below code:
504
+
1. Use the Azure Web PubSub SDK to publish a message to the service. Create a `publish.py` file with the following code:
505
505
506
506
```python
507
507
import sys
@@ -538,7 +538,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
538
538
539
539
# [Java](#tab/java)
540
540
541
-
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:
541
+
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:
@@ -589,7 +589,7 @@ Create a publisher using the Azure Web PubSub SDK to publish a message to the co
589
589
590
590
The `sendToAll()` call sends a message to all connected clients in a hub.
591
591
592
-
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.
592
+
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.
@@ -611,7 +611,7 @@ You can delete the resources that you created in this quickstart by deleting the
611
611
az group delete --name myResourceGroup --yes
612
612
```
613
613
614
-
If you aren't planning to continue using Azure Cloud Shell, you can avoid accumulating costs by deleting the resource group that contains the associated the storage account. The resource group is named `cloud-shell-storage-<your-region>`. Run the following command, replacing `<CloudShellResourceGroup>` with the Cloud Shell group name.
614
+
If you aren't planning to continue using Azure Cloud Shell, you can avoid accumulating costs by deleting the resource group that contains the associated the storage account. The resource group is named `cloud-shell-storage-<your-region>`. Run the following command, replacing `<CloudShellResourceGroup>` with the Cloud Shell group name.
0 commit comments