xmpp 服务所需的 servlet URL 映射 (/_ah/xmpp/message/chat/) 是否限制我仅使用该 servlet 来发送和接收 xmpp 消息?
我的应用程序接收消息,将它们添加到“inQueue”中进行处理,一旦处理完毕,结果就会添加到“outQueue”中。理想情况下,我希望分配给 outQueue 的工作 servlet 发送响应。
我正在使用推送队列,servlet 显然是由 HTTP POST 请求调用的......
当我尝试使用 xmpp 服务从我的 outQueue 工作人员(显然未映射到 /_ah/xmpp/message/chat/ )发送消息时,它预计什么都不做。
在映射到 /_ah/xmpp/message/chat/ 的 servlet 中:
//Generate a Memcache key
String key = generateMemcacheKey(message);
//Serialize the message as xml using getStanza (for now, just put in the senderJID as string)
String senderJIDString = message.getFromJid().getId();
//Cache the message in Memcache
cache.put(key, senderJIDString);
//Enqueue a task for the message
private Queue queue = QueueFactory.getQueue("inQueue");
queue.add(TaskOptions.Builder.withUrl("/xmppParser").param("memcacheKey", key));
在 xmppParser servlet doPost 方法中:
//Extract message from memcache
String key = req.getParameter("memcacheKey");
String recipientJIDString = (String)cache.get(key);
//Todo Detect language
//Todo Parse Message into an Imperative accordingly (For now, just reply hello)
//Todo Handle Session status
//Put Imperative into memcache (For now, just put recipientID in)
cache.put(key, recipientJIDString);
//Enqueue appropriately
Queue queue = QueueFactory.getQueue("outQueue");
queue.add(TaskOptions.Builder.withUrl("/responseServlet").param("memcacheKey", key
));
现在我希望这个 responseServlet 发送回复:
//Get a handler on the memcache
MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
//Extract the key to the response from the request
String key = req.getParameter("memcacheKey");
//Extract the message from the memcache ( For now it's just the JID of the sender)
String recipientJIDString = (String)cache.get(key);
//Parse it into a message (For now just make a simple "I hear you" message)
JID recipientJID = new JID(recipientJIDString);
Message response = new MessageBuilder()
.withMessageType(MessageType.NORMAL)
.withRecipientJids(recipientJID)
.withBody("I hear you")
.build();
//Send the message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
xmpp.sendMessage(response);
servlet 映射都是 kosher,xmpp 服务无法发送消息。它引发了一个空指针异常,但 memcache 查看器确认收件人 JID 也是 kosher ......我猜只有映射到 /_ah/xmpp/message/chat/ 的 servlet 能够发送消息,还是我错了?
由于开发服务器似乎不支持 XMPP,因此我被迫在实时站点本身上进行测试,这增加了我忽略了一些生产环境配置的可能性......
非常感谢!
内存