Sunday, November 29, 2009

Google App Engine XMPP Services Example



Google App Engine released the XMPP Services a while ago. The service started very basic and bad, but since then, it is improving a lot and have potential to be really worthy to build XMPP Services over it.
Unfortunately currently you might only be able to write bots. Which is not that bad specially for developers that are starting with XMPP and App Engine.

The documentation is not that good so far, but it was enough to create an EchoBot Demo App, you can download the full source here.
To use it, just explode the folder, make sure you have Google App Engine SDK configured, set your application ID, and deploy.
I strongly recommend to use Eclipse AppEngine Plugin for those tasks.

Quick Tutorial

Receiving Messages are handled by your application like an HTTP Post Request:
@SuppressWarnings("serial")
public class XmppbotServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {


Parsing Received Messages is piece of cake. AppEngine API is handy in that sense:
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
        Message message = xmpp.parseMessage(req);


Creating a Response Message is also very simple:
JID fromJid = message.getFromJid();
String body = message.getBody();

// Create an Echo Message
Message response = new MessageBuilder().withMessageType(
message.getMessageType()).withBody(body)
.withRecipientJids(fromJid).build();


Now we send it back, without any specialist XMPP Knowledge required.
boolean messageSent = false;
SendResponse status = xmpp.sendMessage(response);
messageSent = (status.getStatusMap().get(fromJid) == SendResponse.Status.SUCCESS);

if (!messageSent) {
// An Error Occurred
}


Now you can create an XMPP Bot with just a few line of simple Java code.
Remarks:

  • Your Bot will auto accept every XMPP contact add request, which is quite handy too. To test your Bot, just open your XMPP Account in your preferred Client. And add the contact: YourAppName@appspotchat.com
  • It will auto-accept your request, and if your service is running, it will be shown as available.
  • You can also use aliases like: Whatever@YourAppName.appspotchat.com

Friday, November 20, 2009

Erlang Version of Jingle Nodes Services is Working!

We are moving very fast with the Erlang version of the Jingle Nodes Services API, after 2 weeks of finishing the Pure Java Version, with great help from contributors, we have a working Erlang Version.
I invite you to check the code at: Jingle Nodes Source
It is based on the excellent exmpp library which besides being rich featured, is also pretty straight forward to use and reliable.

The current version can provide fully working relay channels, but still lacking some features:

  • Detect Inactive Channels
  • Purge Inactive Channels
  • Tracker Services Provider
And indeed we have some bugs to be catch.

Contributions are really welcome!


How to Contribute?
Check the current opened issues: Jingle Node Issues
Send me an email with your intentions or if you wanna go one step ahead, patches are also accepted.

Wednesday, November 11, 2009

Gizmo5 is Now Part of Google's Family

+

Yesterday Google announced the purchase of Gizmo5, a SIP Service provider, that is being around for quite sometime. And I already received some emails questioning about Jingle's future in Google, as Gizmo is a fully SIP based services. So here comes the summary:

Why Gizmo5 and not Skype or other VoIP Service Providers?
  • Gizmo uses SIP, which is an Open Standard. Buying anything closed and proprietary would cost Google a lot of money and huge drawback on integrations.
  • Gizmo is a much more open and known for its interoperability with other SIP Providers. Skype has absolute ZERO interoperability and it is mainly a closed P2P service, which Google already solved in a way more elegant way.
  • Main focus on calling from and to PSTN. Last thing it needs is another P2P Service.
What happens with Jingle on GTalk now?
Nothing! Google needs the flexibility that it offers and specially the natural integration with XMPP Wave Services. I don't see Google releasing Wave Services over SIP for now.
Jingle is by far the best solution for Internet Calling, and this is not a fact only mentioned by XMPP fans, but also by SIP Developers (Asterisk, SER, YATE, etc...).

Will GTalk support SIP now?
That is a tricky question, as there are two very close solutions, with pros and cons that I can't judge from Google's perspective what is better. Basically Google can solve it through:

  1. Jingle/SIP Gateway, XMPP has a very reliable way to interconnect legacy gateways. Nimbuzz for instance already have all its SIP Services working through their XMPP Jingle Clients. They support third party SIP Providers and recently they also have released an embedded solution for calling to PSTN called NimbuzzOut.
  2. Include a SIP Stack in Google Talk Clients. Which is not big deal. As we are plenty of SIP client side solutions and it is very easy to embed.
The point here is that I personally don't think Goggle is willing to implement SIP on  their widgets of web chat voice/video solutions like we have already on GMail. Making Jingle/SIP a necessity anyhow if they also want to allow their users place calls to PSTN also from a Website Flash Widget.
IMHO Google will probably go for a Jingle/SIP gateway, solution that I quite like for two reasons:
I already build such solution, and it works incredibly good! And has great scalability as well.
I also worked last year in the draft specification document that describes the integration Jingle/SIP Interoperability in Media Sessions.
If Google allows me to suggest: Go for Jingle!