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?

More than 3 years have passed since last update.

[Azure] Azure Event Hubsのイベントをブラウザでリアルタイム受信するサンプル

Last updated at Posted at 2021-01-27

これはなに?

Azure Event Hubsのコンシューマ(イベント受信側)をWebブラウザで動かすサンプルです。

ソース全体は https://github.com/sengokyu/Ex.AzureEventHubConsumerOnBrowser に置いてあります。

実行の仕方

事前準備

Event Hubを作成し、接続文字列を取得しておきます。

実行

環境変数を3つ設定します。

環境変数 内容
EVENTHUB_CONNECTION_STRING 取得した接続文字列です。
EVENTHUB_CONSUMER_GROUP 既定では$Defaultです。
EVENTHUB_NAME 作成したEvent Hubの名前です。

パッケージをインストールしてビルドします。

npm install
npm build

dist/index.htmlをブラウザで開きます。開発者コンソールを開きます。

イベントを送信してみます。

node src/producer/send-event.js

実行結果

このような感じにイベントが届きます。

Screencast-2021-01-27-20_46_18.gif

はまったところ

Webpack 5ではprocessを定義してくれなくなったため、自前でwebpack.config.jsに書く必要がありました。

この実装の弱点

接続文字列がJavaScript内にあるので、外からはアクセスできない環境でしか活用できません。

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?