Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating SignalR for microservice with API Gateway

I'm designing a microservice system based on .Net core. The architecture system will look like as the following picture.

enter image description here

The problem is: There is a requirement which have to integrate SignalR (real-time) for notification I've read about SignalR on Microsoft's website. But I consider that where should I put the Hub (API Gateway?, microservice? ...)? How can I apply signalR for this system.

Thanks.

like image 455
Juong David Avatar asked Mar 08 '23 01:03

Juong David


1 Answers

From what I understand, despite it's name, the 'hub' isn't a stand-alone service at all, so you dont have to install it anywhere. SignalR is a library used by your service(s) to directly communicate with your clients. SignalR can be used in two ways, firstly the 'Persistent Connection' API gives the service a way to send arbitrary data to your clients. Its main aim is to abstract away the underlying transport mechanism (e.g. Websockets, Ajax Long polling etc...) similar to WCF. Secondly, the 'Hub' API is an higher level layer of abstraction (built upon the 'Persistent Connection' API) that allows the server to call 'methods' on the client (i.e. similar to RPC in behaviour). Therefore each client has an in-process 'hub' that dispatches incoming messages (from the persistent connection) by calling functions that you write in your client code (i.e. event handlers).

It may also be confusing in the terminology, as in some descriptions I've seen the service hosting the hub instance referred to as a 'hub'. So in your case any of your services could have a built-in hub, or alternatively you could have a dedicated hub service that is shared by your other services. Either way, the hub lives within one or more services.

like image 115
the4thamigo_uk Avatar answered Mar 23 '23 15:03

the4thamigo_uk