如何使用SmackAPI发送广播消息? [英] How to send a broadcast message with SmackAPI?

查看:189
本文介绍了如何使用SmackAPI发送广播消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发使用XMPP相互通信的特殊设备。我正在开发的新API,也应该与这些设备对话。我面临的问题 - 所有这些设备都在为我们拥有的每个客户构建一些小组......所以我们将为每组设备提供一个聊天室,或者为每个客户提供一堆设备;)

We're developing special devices that uses XMPP to talk to each other. A new API i am developing now, should talk to these devices too. The problem i am facing - all these devices are building little groups - for each customer we have... so we will have a chat-room for each group of devices, or, for each of our customer with his bunch of devices ;)

但是现在...... api应该可以与每个连接的设备通话。我不需要真正的广播机制 - 最后,我只会向一个特定设备发送消息..

But now.. the api should be able to talk to every device that is connected. I don't need a real broadcast-mechanism - in the end, i will send a message only to one specific device..

但我不想登录每个聊天室 - 运行一个拥有超过4万客户和更多设备的产品,将以一个有趣的api结束,即在启动时打开超过4万个聊天室...即使没有尝试过这个,我也可以不要想象这样的应用程序运行良好......即使我们几年内可以拥有数百万客户......如果你知道我的意思,我不喜欢与客户数量呈线性关系的解决方案:/

But i don't want to login to each chat-room either - running a product with over 40k customers and much more devices, will end in a funny api, that is opening over 40k chat-rooms at startup... even if don't tried this yet, i can't imagine that an app like this will run well... even though we can have millions of customers in a few years.. i don't like solutions that will grow linear with the amount of customers, if you know what i mean :/

现在,基本上我正在考虑一个解决方案,我可以使用基本的XMPPConnection来完成我的工作。

Now, basically i'm thinking of a solution, where i just can use the basic XMPPConnection to do my stuff.

MyCustomMessage msg = new MyCustomMessage();
msg.setTo("*"); // don't know what to address, i want to send it to "all"
msg.setFrom("ThatAPI"); // just a string telling that is sent from my java api ;)

msg.setEvent(event); // stuff that is coming through the parameters of the method where this code is inside
msg.setCustomStanza(data); // same here

connection.sendPacket(msg); // my try to send it to all till now..

Ignite Realtime Forums中的某个地方我有阅读一个解决它的人,但他说的一切都是它现在正在工作,我通过连接的sendPacket推送我的信息......好的,我的尝试似乎不起作用:(

Somewhere in the Ignite Realtime Forums i have read of one guy who "solved" it, but everything he says is "it's working now, i push my message through the sendPacket of Connection"... ok nice, my attempt of this seems not to work :(

任何更好的想法/实际实现如何才能正常工作?

Any better ideas/real implementations how this will work fine?

基本上我开始认为XMPP不会是最好的技术实现这样的事情 - 我希望我能有一个真正的/基本的套接字实现,这样的事情将是小菜一碟..但我无法选择 - 第三方系统已经实施了XMPP。 ..没有足够的时间来改变所有这些...就好像你想知道为什么我们在XMPP上尝试这个..

Basically i start to think that XMPP will not be the best technology to achieve something like this at all - i wish i could have a real/basic socket-implementation where something like this would be piece of cake.. But i can't choose - the third-party-system has implemented XMPP already... not enough time to change all of this... Just if you're wondering why we try this on XMPP..

推荐答案

你似乎有一些相互矛盾的要求,你现在要发送给所有设备,但后来只发送一个特定的设备。两个模型都需要在同时,或者你打算转换?如何处理将是不同的解决方案。

You seem to have some conflicting requirements in that you want to send to all devices now, but only 1 specific device later. Are both models required at the same time, or do you plan on switching? How either is done would be different solutions.

至于你目前的方法,我认为 pubsub 比你的聊天室方法更有意义,因为它面向传递给订阅者的通用消息。

As for your current approach, I think pubsub would make more sense than your chatroom approach, as that is oriented to generic message passing to subscribers.


  • 您可以为每个客户设置一个pubsub节点,以便向其设备的所有
    发送消息。

  • 对于所有人的广播,你可以让所有设备
    订阅一个pubsub节点。

因此,您可以通过发送到相应的pubsub节点来控制广播和群组消息。

Thus you control broadcast and group messages by sending to the appropriate pubsub node.

要发送到特定设备,这只是一个sendPacket到特定的实体,没有什么特别的。

For sending to a specific device, that is just a sendPacket to the specific entity, nothing really special there.

这篇关于如何使用SmackAPI发送广播消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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