App Engine 渠道部署
我创建了一个拥有约 50 个用户的应用程序。 我正在尝试使用通道 API,但在测试消息发送时遇到了问题。 我将令牌保存到数据库中,这样如果用户使用相同的界面打开多个选项卡,我就可以使用相同的令牌,并且我有一个 servlet,可以在令牌过期时重置我的令牌。
它工作正常,直到我重新部署我的应用程序或更改我的应用程序的版本。我停止接收消息。如果我尝试使用旧应用程序版本令牌打开一个通道,它不会抛出错误或任何内容,它会打开它,但我仍然没有收到该通道上的消息。
如果我重置我的令牌,它会再次正常工作。
有谁知道这个错误的解决方案,或者以前有人遇到过吗?我经常在人们工作时进行部署,所以我不能忽视它。
我最好的猜测是 ChannelServiceFactory.getChannelService()
返回 ChannelService
的不同实例,因此当我调用 channelService.sendMessage("id","message"); 时
它将其发送到不同的通道。
I created an application that has ~50 users.
I am trying to use channel API but I've run into a problem while testing with message send.
I am saving the token into the database so i can use the same token if an user opens multiple tabs with the same interface and i have a servlet that resets my token when it expires.
It works fine until I redeploy my application or change the version of my app. I stop receiving messages. If I try to open a channel with the old app version token it doesn't throw an error or anything, it opens it but I still don't receive messages on that channel.
If I reset my token it works OK again.
Does anyone know of a solution to this bug, or has anyone had it before? I deploy often while people are working so I can't ignore it.
My best guess is that ChannelServiceFactory.getChannelService()
returns a different instance of ChannelService
so when I call channelService.sendMessage("id","message");
it sends it to a different channel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法解释为什么存储的令牌在重新部署您的应用程序时不起作用(它们应该),但我可以解释为什么它们在您更改版本时不起作用。简而言之,令牌特定于应用程序版本。
首先,这样做的原因是:我们希望确保在不同版本中发送不同数据或更改消息格式或其他任何内容的应用程序不会跨版本边界发送消息。就像您不希望 v1 中的 javascript 包针对 v2 上的 servlet 进行渲染一样,您也不希望 v1 的 javascript 消息处理程序从 v2 servlet 接收消息(反之亦然)。
因此,希望能够弄清楚发生了什么:
通道是由您的 appid、应用程序版本以及您在调用 createChannel 或 sendMessage 时提供的 clientid 的组合来标识的。 Channel API 的实现不存储任何 appid/clientid 的映射 ->令牌。为了大大简化,您可以将 createChannel 视为执行如下操作:
而 sendMessage 则如下所示:
在客户端,负责通道的 servlet 解密令牌并绑定到由相同方法创建的 JID 标识的端点作为
sendMessage
函数。结果是令牌仅对从创建它们的应用程序的同一版本发送的消息有效。
I can't explain why stored tokens wouldn't work on re-deploying your app (they should), but I can explain why they don't work when you change versions. Briefly, tokens are specific to an app version.
First, the reason for this: we want to ensure that applications that send different data or change message formats or whatever in different versions don't send messages across version boundaries. In the same way that you don't want your javascript bundle from v1 rendering against servlets on v2, you wouldn't want v1 your javascript message handlers receiving messages from v2 servlets (or vice versa).
So, to hopefully make it clear what's going on:
A channel is identified by a combination of your appid, your app version, and the clientid that you provide when you call createChannel or sendMessage. The implementation of the Channel API doesn't store any mapping of appid/clientid -> token. To greatly simplify, you can think of createChannel as doing something like this:
and sendMessage is like this:
and on the client side, the servlet responsible for the channel decrypts the token and binds to the endpoint identified by a JID created by the same method as the
sendMessage
function.The upshot is that tokens are only valid for messages sent from the same version of the app that created them.