It sounds like you want to diectly connect EventHub via a browser with websocket, as I known, the only way to realize it is to use AMQP over WebSocket to connect EventHub.
There is a MSDN blog introduce this topic Connect to Azure Event Hub in browser ( using AMQP over WebSockets )
, and the other blog of the same author introduce How to use AMQP protocol in Browser (JavaScript)
. And you can get rhea.js
from its GitHub repo https://github.com/amqp/rhea/tree/master/dist
.
Meanwhile, according to the information from the source codes of @azure/event-hubs
, it seems to support the feature of AMQP over WebSocket in browser, as the figure below comes from the source code https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/src/impl/eventHubClient.ts#L259.
And there is a sample code of websockets.ts
for EventHubs, and it requires @azure/event-hubs
version next
in its package.json
. I think you just need to use WebSocket
in browser instead of WebSocket
from import WebSocket from "ws";
in the sample, then you could make it works in browser.