J. Doe
J. Doe

Reputation: 530

Communication between two signalR Core Hubs

I have two signalR Core Typescript Apps (A & B) with their own SignalR Core C# Hub (C & D).

No I want to trigger something from A in B. My plan was to send the trigger message from A to C, then C redirects it to D and sends it to B. The same should be possible in the other direction as well.

The Hubs are independent of each other, so making one Hub a part of the other doesnt work for me. The only solution I came up with is to use two SignalR Core C# Clients to communicate between the Hubs, but that seems like a big overhead. Or is it the way to go?

Upvotes: 1

Views: 2659

Answers (2)

Fei Han
Fei Han

Reputation: 27793

I have two signalR Core Typescript Apps (A & B) with their own SignalR Core C# Hub (C & D).

No I want to trigger something from A in B.

You can refer to the following possible approaches to achieve above requirement.

Approach 1: modify your implementation and merge existing functionality into single Hub class, then you can make SignalR Typescript client apps (A & B) connect to same hub server and communicate with each other.

Approach 2: establish connections to both Hub C and Hub D on SignalR Typescript client apps (A & B) for each client user, so that user using Typescript client app A can also communicate with users from Typescript client app B.

Approach 3: as you mentioned, install Microsoft.AspNetCore.SignalR.Client package and implement SignalR .NET client logic on Hub server project (A & B), which would make them act as both server and a SignalR .NET client.

Approach 4: as @Kiril1512 mentioned, can implement SignalR .NET client logic in a separate project that might be a queue-based (or servicebus-based etc) job. If user from SignalR Typescript client app A want to communicate to users from SignalR Typescript client app B connecting to Hub D, he can send specific message to Hub C to add a new queue message, then it will trigger that job to invoke Hub method of Hub server D to push message(s) to specific users from SignalR Typescript client app B, like below.

enter image description here

Upvotes: 1

Kiril1512
Kiril1512

Reputation: 3621

First of all, this is a opinion question so it will be closed maybe.

But I believe the better approach is using something like Service Busand implement event based communication. So something happens at A and you invoke hub method at C, then send a event to D and it will trigger via signalR the A. Using event bus will add the option to add for example another hub (E) that could receive those events and do something else.

Upvotes: 1

Related Questions