我正在使用 EventMachine + em-http-request 来请求 Twitter 流 API。
它工作得很好,但现在我想得到它的错误证明。
检测连接是否停止的最佳方法是什么? (为了尝试自动重新连接)。
我有一个临时解决方案:每次从流方法收到新块时,我都会保存当前时间戳。 periodictimer 正在检查此时间戳,并在最后一个时间戳超过 30 秒时发出重新连接。此解决方案的问题在于,它对停滞的连接和没有内容的工作连接没有区别。
感谢您的帮助。
I'm using EventMachine + em-http-request to request Twitter streaming API.
It works perfectly, but now I would like to get it error proof.
What would be the best way to detect that the connection is stalled? (in order to try an auto-reconnect).
I have a temporary solution: each time I receive a new chunk from the stream method, I save the current timestamp. A PeriodicTimer is checking this timestamp and issues a reconnection whenever the last-timestamp is more than 30secs old. The issue with this solution is that it makes no difference between a stalled connection and a working connection with no content.
Thanks for your help.
发布评论
评论(1)
您可以将
errback
回调附加到您的请求对象:从 em-http-request wiki:
就我个人而言,我更喜欢使用 Faraday 而不是使用原始 em-http-request 库:
这是一个 法拉第教程。如果您正在使用 Twitter Streaming API,这里有一个陷阱留意。祝你好运!
You can attach an
errback
callback to your request object:From the em-http-request wiki:
Personally, I prefer to use Faraday rather than working with the raw em-http-request library:
Here's a tutorial for Faraday. And if you're working with the twitter streaming API, here's a gotcha to watch out for. Good luck!