Stomp - 多个订阅,每个订阅都有一个唯一的处理程序
我正在使用 Stomp / Orbited 来实现 Comet 功能。
为了处理多个通道,我最终这样做:
stomp.onmessageframe = function(frame) {
if (frame.headers['destination'] == '/thisFeed/') { //处理这个Feed }
if (frame.headers['destination'] == '/thatFeed/') { //处理那个Feed ....
我想这没关系。但是,如果我在加载时不知道如何处理提要怎么办?我希望能够做这样的事情:
stomp.subscribe('someOtherFeed', someOtherFeedHandler);
这样,当我订阅时,我就可以定义处理程序。
I am using Stomp / Orbited for Comet functionality.
In order to deal with multiple channels, I end up doing this:
stomp.onmessageframe = function(frame) {
if (frame.headers['destination'] == '/thisFeed/') {
//handle thisFeed
}
if (frame.headers['destination'] == '/thatFeed/') {
//handle thatFeed
}
....which is OK, I guess. But what if I don't know, at load time, how I want to handle a feed? I want to be able to do something like this:
stomp.subscribe('someOtherFeed', someOtherFeedHandler);
That way, when I subscribe, I can define the handler then and only then.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了一种解决方案,但它离漂亮还很远。
当我创建 stomp 消息时,我添加一个“handler”属性作为标头,就像在 python 中一样:
然后,在 javascript 中:
...so then,函数 llamas() 被调用。然后我可以在任何我想要的地方定义(和重新定义)美洲驼。
现在我确信这不是最佳解决方案。另一方面,我确实喜欢它给了我一点灵活性来指定我想在 python 中使用的处理程序。但说实话,我认为有更好的方法。
I have come up with one solution, but it's so very far from pretty.
When I create the stomp message, I add a "handler" property as a header, like so in python:
Then, in the javascript:
...so then, the function llamas() gets called. I can then define (and redefine) llamas anywhere I want.
Now I'm sure this can't be the optimal solution. I do, on the other hand, like that it gives me a bit of flexibility to specify the handler I want to use right in python. But seriously, I'm thinking there is a better way.