Azure

Chat Software Utilizing Azure Net PubSub Service (Preview)

Azure Net PubSub service, as its title says, relies on a publish-subscribe sample and permits us to construct real-time internet functions.

 

A few of the common examples the place we are able to use this service are, for any chat-based functions, and collaboration functions, like whiteboarding functions. We are able to additionally use this service for any utility which wants prompt push notifications. In truth, there are a lot of extra examples, we are able to take into consideration.

 

The most effective half is, we are able to use Azure Net PubSub service on all of the platforms which help WebSocket APIs and it permits as much as 100 thousand concurrent connections at any

level of time.

 

Elements required to create a fundamental chat utility,

  1. An occasion of Azure Net PubSub Service
  2. Writer utility
  3. Subscriber utility

To learn about how you can create and use these elements, I’ve created an entire video demonstrating these,

 

 

C# Code for Writer and Subscriber

 

Under is the C# code for the respective lessons,

 

Writer.cs

  1. var connectionString = “Your_ConnectionString_Here”;  
  2. var hub = “Your_Hub_Here”;  
  3. var serviceClient = new WebPubSubServiceClient(connectionString, hub);  
  4. whereas (true) {  
  5.     Console.Write(“Enter message: “);  
  6.     string message = Console.ReadLine();  
  7.     serviceClient.SendToAll(message);  
  8. }  

Subscriber.cs

  1. var connectionString = “Your_ConnectionString_Here”;  
  2. var hub = “Your_Hub_Here”;  
  3.   
  4. var serviceClient = new WebPubSubServiceClient(connectionString, hub);  
  5. var url = serviceClient.GetClientAccessUri();  
  6. utilizing(var consumer = new WebsocketClient(url)) {  
  7.     consumer.MessageReceived.Subscribe(msg => Console.WriteLine($ “Message acquired: {msg}”));  
  8.     await consumer.Begin();  
  9.     Console.WriteLine(“I am related.”);  
  10.     Console.Learn();  
  11. }  

Hope you loved studying concerning the Azure Net PubSub service.

Tags
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close