com*_*tta 3 java google-app-engine xmpp openfire
我可能知道你们用什么集成技术来实现现有XMPP服务器的外部组件(例如ejabberd或OpenFire).是通过直接向另一个用户@ externaldomain发送xmpp消息还是使用urlfetch等机制?
Google应用引擎(Gae)确实像CLIENT一样支持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);
}
Run Code Online (Sandbox Code Playgroud)
收到消息
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
}
}
Run Code Online (Sandbox Code Playgroud)
请记住,JID只能是yourappid@appspot.com或者是foo@yourappid.appspotchat.com, 因为Google域名尚不支持.
例如,您可以使用以下简单页面制作玩具Gae应用程序:
要测试您的应用程序:
如果您的个人XMPP服务器(openfire)启动并运行,只需跳过步骤1并使用您的域帐户接收来自您的花式Gae应用程序的消息.
查看XMPP 消息传递以了解其工作原理.
归档时间: |
|
查看次数: |
2191 次 |
最近记录: |