App Engine 通道 API 不返回任何消息
问题描述:频道消息没有返回到ajax脚本。 最初,消息被传递到客户端,但是当我在js中设置更大的超时时,问题出现了:
goog.appengine.Socket.POLLING_TIMEOUT_MS = 5000; //每5秒轮询一次
我添加了一个非常基本的Python代码来测试Channel API是否在我的Google App Engine应用程序中工作。
index:
token = channel.create_channel(CHANNEL_NAME)
channel.send_message(CHANNEL_NAME, message)
#token is passed to template
additional_view:
#is another view, trigger manually from browser after index
from django.utils import simplejson
channel.send_message(CHANNEL_NAME, simplejson.dumps(data))
在客户端,我有一个带有 onMessage 代码的常规 js。
问题是没有消息返回给客户端请求。它们对于轮询 ajax 都是空的(如 Firebug 中所示)。在应用程序日志中,我可以看到通道已创建:
“使用客户端 ID 广播创建通道令牌通道-2382918168-广播” 稍后发送消息,但带有评论:
中间有这些请求:
INFO 2011-08-03 14:33:32,000 dev_appserver.py:4248] "POST /_ah/channel/connected/ HTTP/1.1" 404 -
INFO 2011-08-03 14:33:33,780 dev_appserver.py:4248] "POST /_ah/channel/disconnected/ HTTP/1.1" 404 -
** ....消息文本...到带有密钥的通道(广播):没有连接客户端***
通道/消息如何在更深层次上发挥作用?如果没有客户端连接或新连接的客户端检索消息,消息是否会丢失? 如果由于某种原因我创建了一个同名的频道,它会破坏里面未传递的消息吗?
Problem description: channel messages no returned to ajax script.
Initially, messages are delivered to clietn side, but the problem appears when I set larger timeout in js:
goog.appengine.Socket.POLLING_TIMEOUT_MS = 5000; //poll every 5 seconds
I've added a very basic Python code to test if Channel API works in my Google App Engine app.
index:
token = channel.create_channel(CHANNEL_NAME)
channel.send_message(CHANNEL_NAME, message)
#token is passed to template
additional_view:
#is another view, trigger manually from browser after index
from django.utils import simplejson
channel.send_message(CHANNEL_NAME, simplejson.dumps(data))
At client side I have a regular js with onMessage code.
The problem is that no messages are returned to client-side requests. They all come empty to polling ajax (as seen in Firebug). In application log I can see that channel is created:
"Creating channel token channel-2382918168-broadcast with client id broadcast"
and later message is sent but with a comment:
in between come these requests:
INFO 2011-08-03 14:33:32,000 dev_appserver.py:4248] "POST /_ah/channel/connected/ HTTP/1.1" 404 -
INFO 2011-08-03 14:33:33,780 dev_appserver.py:4248] "POST /_ah/channel/disconnected/ HTTP/1.1" 404 -
** ....message text...to channel with key (broadcast): no clients connected***
How does channel/message function at deeper level? Are messages lost if no clients are connected or they are retrived by newly connect clients?
If for some reason I create a channel with the same name, would it distroy undelivered messages it has inside?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将
POLLING_TIMEOUT_MS
设置为高于 1.5 秒,dev_appserver 会假设您已断开连接。它不能通过生产中的轮询来工作,因此您不必真正担心超时。
编辑:刚刚看到罗伯特的评论;就我个人而言,如果我在 Chrome/Safari/Firefox 中将轮询设置为 3 秒,我什至会遇到问题。现在,我的应用程序上只有
?disable_channel=true
查询字符串,这样我就可以运行它们,而无需因 CPU 使用率而导致笔记本电脑着火。Stay away from setting the
POLLING_TIMEOUT_MS
higher than 1.5 sec, the dev_appserver will assume you have disconnected.It does not work via polling in production, so you do not have to worry about the timeout really.
Edit: just saw Robert's comment; personally I have even had issues if I set the polling to 3sec in Chrome/Safari/Firefox. I now just have
?disable_channel=true
query strings on my apps so that I can run them without setting my laptop on fire with the CPU usage.