Open In App

Microsoft Azure – Messaging with Azure Web PubSub

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to publish and subscribe messages with Azure Web PubSub. Azure Web PubSub provides real-time web socket communication between clients without the need to pull for messages or set up complicated plumbing.

Implementation:

Follow the below-given steps to publish and subscribe messages with Azure Web PunSub:

Step 1: Let’s start by creating a new Azure Web PubSub service. 

Step 2: Select a Resource group and give the service a name, we’ll leave the rest as it is. Let’s create the service. 

Step 3: In the Azure Web PubSub service. We need to connect to it, so here is the connection string. We’ll use that later.

We can also scale the service to support more client connections.

Step 4: We will use an application from this GitHub repository in the article. This contains two console apps that subscribe to Azure Web PubSub and publish messages.

Step 5: Here, for instance, all we need to do is connect to Azure Web PubSub and send the message. 

Step 6: We’ve downloaded the sample applications here, we’ll start with the subscriber. Let’s open a command prompt for it. Now, run it with .NET run and the connection string and a name for the hub, which can be anything. It’s connected now.

Step 7: Now for the publisher. For this one, we also use .NET run, the connection string, the hub name, and also a message, and run it. Here at the top is the subscriber app, it has received the “hello” message that has just been sent.

You might be wondering what the difference between Azure Web PubSub and Azure SignalR Service is, as they seem to do the same thing. Well, there are some big differences. Azure Web PubSub is simple. It is only you and your WebSockets, no other protocols. It is a very plain service with no support to automatically reconnect clients. There’s also no fallback protocol if the WebSocket connection fails. 

The Azure SignalR Service does a bit more. Its SignalR protocol can keep connections alive and can reconnect lost connections. It also supports more communication protocols like remote procedure calls or RPC and streaming between clients. The SignalR Service also uses a fallback protocol when it can’t use a WebSocket connection. 

If you need more capabilities out of the box, use Azure SignalR. If you don’t, use Azure Web PubSub. Azure Web PubSub is an accessible real-time message service that you can use with any programming language that supports WebSockets connections. 


Last Updated : 31 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads