如何做好可靠的消息传递与SignalR? [英] How to do guaranteed message delivery with SignalR?

查看:584
本文介绍了如何做好可靠的消息传递与SignalR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用C#和SignalR实时客户端 - 服务器应用程序。我要以最快的速度将消息发送给客户端成为可能。
在服务器上我的code:

I am developing real-time client-server application using C# and SignalR. I need to send messages to client as fast as possible. My code on server:

for (int i = 0; i < totalRecords; i++)
{
    hubContext.Clients.Client(clientList[c].Key).addMessage(
    serverId, RecordsList[i].type + RecordsList[i].value);
    Thread.Sleep(50);       
}

如果有延时> = 50毫秒一切工作的完美,但如果没有延迟或延时小于50毫秒的一些邮件丢失。
我需要尽可能快地发送的消息刻不容缓。
我想我需要检查,如果接收到的信息只发送另一个之后。结果
如何做一个正确的方式?

If there is delay >=50 ms everything working perfect, but if there is no delay or delay is less then 50 ms some messages are missing. I need to sent messages as fast as possible without delay. I guess I need to check if message received and only after send another one.
How to do it in a right way?

推荐答案

SignalR并不能保证邮件传递。因为当你调用客户端的方法SignalR不会阻塞,你可以调用客户端的方法非常快,你已经发现。不幸的是,客户可能并不总是准备好立即接收消息,一旦你给他们,让SignalR具有缓冲消息。

SignalR doesn't guarantee message delivery. Since SignalR doesn't block when you call client methods, you can invoke client methods very quickly as you've discovered. Unfortunately, the client might not always be ready to receive messages immediately once you send them, so SignalR has to buffer messages.

一般来说,SignalR将缓冲到每个客户端1000的消息。一旦客户超过1000条消息落后,它将开始失踪的消息。 1000这DefaultMessageBufferSize可以增加,但这会增加SignalR的内存使用,它仍然不能保证消息的传送。

Generally speaking, SignalR will buffer up to 1000 messages per client. Once the client falls behind by over 1000 messages, it will start missing messages. This DefaultMessageBufferSize of 1000 can be increased, but this will increase SignalR's memory usage and it still won't guarantee message delivery.

<一个href=\"http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/signalr-performance#tuning\">http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/signalr-performance#tuning

如果你想保证的消息传递,你将不得不自己ACK他们。你可以如你所说,只有previous消息被确认后,发送邮件。您也可以一次ACK多条消息在等待着每个消息的ACK太慢了。

If you want to guarantee message delivery, you will have to ACK them yourself. You can, as you suggested, only send a message after the previous message has been acknowledged. You can also ACK multiple messages at a time if waiting for an ACK for each message is too slow.

这篇关于如何做好可靠的消息传递与SignalR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆