The order of messages in SingalR - how to ensure it

I use SingalR in an application that sends a lot of messages in a short amount of time. let's say I have client A and client B. Client A just sends messages and client B just by listening to the messages. Client A sends the following messages in the following order: A-> B-> C-> D

What I see is that client B sometimes receives messages in a different order, for example: B-> A-> C-> D

It is important to maintain the same order that I sent messages. I looked online and I found people saying that I should use async-await for a function on a hub that processes these messages.

public async Task hubMethod(msgObject msg) { await Clients.All.message(msg); } 

I am not sure how this helps, because every time I make a call from client A, singalR must create a new instance of the hub. The only thing he does is wait for singalR to finish doing everything he can do on the server to send a message to another client and notify his client A.

So my question is whether there is a singalR or asp.net mechanism that ensures that I receive messages in the correct order on another client or whether I need to write my own mechanism (server or client) that reorders the messages if they are not in alright, and if so, is there a library that already does this?

+6
source share

Source: https://habr.com/ru/post/1014444/


All Articles