Can node JS recieve signalR messages without a frontend?

Aaron Manill 86 Reputation points
2022-02-07T17:34:11.43+00:00

I am looking to implement an automated printing service where a system running nodeJS can be notified from serverless SignalR that a file can now be retrieved for printing. Is this something that is achievable? From the documentation I've been able to find so far on javascript based signalR it looks like almost all of the signalR data processing is being done on a client end, and that nodeJS is just being used to actually point the client to the signalR service.

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
66 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
120 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 26,156 Reputation points Microsoft Employee
    2022-02-08T15:56:16.077+00:00

    I think using a Web PubSub instance would be a better fit. It encapsulates SignalR service into a simplified publisher/receiver model. This tutorial walks you through creating a simple publisher and subscriber app.

       // * publisher * //  
         
       const { WebPubSubServiceClient } = require('@azure/web-pubsub');  
         
       const hub = "pubsub";  
       let service = new WebPubSubServiceClient(process.env.WebPubSubConnectionString, hub);  
         
       // by default it uses `application/json`, specify contentType as `text/plain` if you want plain-text  
       service.sendToAll(process.argv[2], { contentType: "text/plain" });  
         
         
       // * subscriber * //  
       const WebSocket = require('ws');  
       const { WebPubSubServiceClient } = require('@azure/web-pubsub');  
         
       async function main() {  
         const hub = "pubsub";  
         let service = new WebPubSubServiceClient(process.env.WebPubSubConnectionString, hub);  
         let token = await service.getClientAccessToken();  
         let ws = new WebSocket(token.url);  
         ws.on('open', () => console.log('connected'));  
         ws.on('message', data => console.log('Message received: %s', data));  
       }  
         
       main();  
    

    Your publisher can be an Azure Function that's either triggered through HTTP, Timer, or a Queue and use a webPubSub as an output to broadcast and any connected subscriber will receive the message. This serverless notification tutorial demonstrates how to set this up. Your subscriber should be able to run headless but using node, you would still need to run it locally.

    0 comments No comments

0 additional answers

Sort by: Most helpful