0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Web PubSub - Azure - Memo

Last updated at Posted at 2023-08-26

(自分用メモ)
Web PubSub を試す。

環境

azコマンドでwebpubsubを使用できるようにする
az extension add --upgrade --name webpubsub
各種設定値
uniq=2311  # 他人とかぶらない文字列
resgr=trial # リソースグループ名
location=eastus # データセンター
pubsub=pubsub$uniq # PubSubリソース名
hub=hub1 # hub名
user=uid # ユーザ名

Azureリソース準備

参考

リソース準備
uniq=2311
resgr=trial
location=eastus
pubsub=pubsub$uniq

az group create --name $resgr --location $location
az webpubsub create --name $pubsub --resource-group $resgr --sku Free_F1 --location $location
接続文字列取得
az webpubsub key show --name $pubsub --resource-group $resgr --query primaryConnectionString

※Portalでは、Azure portal > Web PubSubリソース > キー > Primary 接続文字列

Hub管理
hub=hub1
user=uid

az webpubsub hub list --name $pubsub --resource-group $resgr
az webpubsub hub create   --name $pubsub --hub-name $hub --resource-group $resgr

サンプルコード

Azure SDK版

git clone https://github.com/kyoya-p/samples
cd samples/2023/Azure/WebPubSub
クライアント(モニター)起動
az webpubsub client start --name $pubsub --hub-name $hub --resource-group $resgr --user-id $user
受信側アプリ実行
token=`az webpubsub key show --name $pubsub --resource-group $resgr -o yamlc --query primaryConnectionString`

npm i
npx tsc
node build/sub.js "$token" $hub
送信側アプリ実行
token=`az webpubsub key show --name $pubsub --resource-group $resgr -o yamlc --query primaryConnectionString`

npm i
npx tsc
node build/pub.js "$token" $hub

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?