Do I Need Azure Event Hubs for Azure Web PubSub with Socket.io?

Baibhav M 0 Reputation points
2023-10-07T08:28:18.34+00:00

I'm working on integrating Azure Web PubSub with Socket.io for real-time communication in my Node.js application.

My question is, do I need to create Azure Event Hubs in my Azure configuration to use Azure Web PubSub with Socket.io in this way? What is the relationship between Azure Web PubSub and Azure Event Hubs, and when is it necessary to use both services together?

I want to ensure that I have the correct Azure services configured to enable seamless real-time communication in my application. Any guidance on this matter would be appreciated.

In my code, I'm using Azure Web PubSub with Socket.io as follows:

await useAzureSocketIO(ioFastParty, {
  hub: "fast_hub",
  connectionString:
    process.argv[2] || process.env.WebPubSubConnectionString,
});

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
75 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Konstantinos Passadis 19,166 Reputation points MVP
    2023-10-10T18:00:06.93+00:00

    Hello @Baibhav M !

    Welcome to Microsoft QnA!

    Lets sum it up for you !

    The Azure Web PubSub Service helps you build real-time messaging web applications using WebSockets and the publish-subscribe pattern easily. This real-time functionality allows publishing content updates between server and connected clients (for example a single page web application or mobile application). The clients do not need to poll the latest updates, or submit new HTTP requests for updates.

    There are many different ways to program with Azure Web PubSub service, as some of the samples listed here:

    • Build serverless real-time applications: Use Azure Functions' integration with Azure Web PubSub service to build serverless real-time applications in languages such as JavaScript, C#, Java and Python.
      
    • Use WebSocket subprotocol to do client-side only Pub/Sub - Azure Web PubSub service provides WebSocket subprotocols to empower authorized clients to publish to other clients in a convenience manner.
      
    • Use provided SDKs to manage the WebSocket connections in self-host app servers - Azure Web PubSub service provides SDKs in C#, JavaScript, Java and Python to manage the WebSocket connections easily, including broadcast messages to the connections, add connections to some groups, or close the connections, etc.
      
    • Send messages from server to clients via REST API - Azure Web PubSub service provides REST API to enable applications to post messages to clients connected, in any REST capable programming languages.
      

    Azure Event Hubs is a cloud native data streaming service that can stream millions of events per second, with low latency, from any source to any destination. Event Hubs is compatible with Apache Kafka, and it enables you to run existing Kafka workloads without any code changes.

    Using Event Hubs to ingest and store streaming data, businesses can harness the power of streaming data to gain valuable insights, drive real-time analytics, and respond to events as they happen, enhancing overall efficiency and customer experience.

    Summary:

    • Azure Web PubSub is suitable for handling real-time messaging scenarios.
      
    • Azure Event Hubs is optimal when you need to efficiently ingest, buffer, store, and process large volumes of events/data streams.
      

    So you don't NEED to but you can if you want to use Web PubSub for real-time communication and then pushing the data/messages into Event Hubs for further analysis or processing.

    Also :

    https://learn.microsoft.com/en-us/azure/azure-web-pubsub/socketio-overview

    Socket.IO is a widely popular open-source library for real-time messaging between clients and a server. Managing stateful and persistent connections between clients and a server is often a source of frustration for Socket.IO users. The problem is more acute when multiple Socket.IO instances are spread across servers.

    Azure provides a fully managed cloud solution for Socket.IO. This support removes the burden of deploying, hosting, and coordinating Socket.IO instances for developers. Development teams can then focus on building real-time experiences by using familiar APIs from the Socket.IO library.

    So if :

    You want to ingest and process the messages/events coming through your real-time communication layer.
    
    You have further data analytics, processing, or storage requirements.
    

    Then yes you can integrate both but it is not a requirement !

    References :

    https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-samples

    https://learn.microsoft.com/en-us/azure/azure-web-pubsub/socketio-overview

    https://learn.microsoft.com/en-us/azure/azure-web-pubsub/overview


    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.