我可能知道你们用什么集成技术来实现现有XMPP服务器的外部组件(例如ejabberd或OpenFire)。是通过直接向另一个用户@ externaldomain发送xmpp消息还是使用urlfetch等机制?

有帮助吗?

解决方案

Google应用引擎(Gae)支持XMPP,就像客户端一样。

使用XMPP Gae JAVA客户端功能你可以:

发送讯息

JID jid = new JID("youraccount@jabber.org");
Message msg = new MessageBuilder()
    .withRecipientJids(jid)
    .withBody("Hello i'm a fancy GAE app, how are you?")
    .build();                    
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(jid).isAvailable()) {
   SendResponse status = xmpp.sendMessage(msg);               
}

收到留言

public class XMPPReceiverServlet extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse res)
          throws IOException {
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = xmpp.parseMessage(req);    
    JID fromJid = message.getFromJid();
    String body = message.getBody();
    //Save to Big Table
  }
}

请记住,JID可以只是 yourappid@appspot.com foo@yourappid.appspotchat.com 因为Google域名尚不支持。

例如,您可以使用以下简单页面制作玩具Gae应用程序:

  1. 发送文字的html表单
  2. 一个html表,显示接收并存储到大表的消息列表。
  3. 测试您的应用程序:

    1. 在jabber.org上创建一个帐户
    2. 下载Smack
    3. 尝试从Smack发送消息至yourappid@appspot.com
    4. 尝试从Gae App发送消息至youraccount@jabber.org
    5. 如果您的个人XMPP服务器(openfire)启动并运行,只需跳过步骤1并使用您的域帐户接收来自您的花式Gae应用程序的消息。

      查看XMPP 邮件传递,了解其工作原理。

其他提示

App Engine支持非常有限的XMPP子集。基本上,您可以发送消息(通过API),并且您可以接收消息(它们作为HTTP请求进入)。

Java API
Python API

您可以在现有XMPP服务器上安装外部组件,以使用您的应用引擎代码发送和接收消息。该组件必须跟踪您想要从您的应用发送和接收的内容。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top