我可能知道你们用什么集成技术来实现现有XMPP服务器的外部组件(例如ejabberd或OpenFire)。是通过直接向另一个用户@ externaldomain发送xmpp消息还是使用urlfetch等机制?
答案 0 :(得分:6)
Google应用引擎(Gae)支持XMPP,就像客户端一样。
使用XMPP Gae JAVA client功能,您可以:
发送讯息
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应用程序:
测试您的应用程序:
如果您的个人XMPP服务器(openfire)启动并运行,只需跳过步骤1并使用您的域帐户接收来自您的花式Gae应用程序的消息。
了解XMPP message delivery以了解其工作原理。
答案 1 :(得分:1)
App Engine支持非常有限的XMPP子集。基本上,您可以发送消息(通过API),并且您可以接收消息(它们作为HTTP请求进入)。
您可以在现有XMPP服务器上安装外部组件,以使用您的应用引擎代码发送和接收消息。该组件必须跟踪您想要从您的应用发送和接收的内容。