Adventures in Jabberlang

For part 3 of this ‘exciting’ series, I’m adding Jabberlang onto the existing setup to provide easy access to two-way XMPP messaging. If I was just sending, I would have restricted myself to tinkering with the code that Sam Ruby kindly piped up with the other day.

Similarly, if I was more serious about this I’d probably be writing my own XMPP client library, since Jabberlang currently leaves more than a bit to be desired. However, this is strictly a half-hour here and there evening hobby project – a refreshing interlude from the daily grind of watching an egg-timer float in front of Visual Studio 2005. As such, I don’t mind (for now) treading carefully around horrors such as this:

Message = io_lib:format("<message to='~s' type='~s'>
  <body>~s</body></message>",[To, Type, Body])

By the way, if it hadn’t become obvious already, the purpose behind documenting all this is so I can go back and script it when I need to set up an array of identical machines.

So, back to the task at hand. It’s not easy to find a version of Jabberlang that works. I got fed up of trying to patch various problems in 0.2 caused by API changes in ejabberd (on which jabberlang depends), and moved on to trying to fix the broken build system in more recent SVN version. In the end though, I found a sweet-ish spot at revision 5:

svn co -r 5 http://svn.process-one.net/jabberlang/trunk jabberlang
cd jabberlang
erl -pa ebin -make
cd ..

Starting up Erlang to use this requires the following:

EJABBERD_SO_PATH=/var/lib/ejabberd/priv/lib
erl -pa ../jabberlang/ebin /var/lib/ejabberd/ebin

And just to prove it’s all working, a quick test program:

-module(jerltest).
-export([main/0]).
 
main()->
   {ok,X}=xmpp:start("ubuntu01",5222),
   xmpp:set_login_information(X,"test",{password,"pwd"}),
   xmpp:connect(X),
   xmpp:subscribe(X,"ciaran@a.remote.server"),
   xmpp:message(X,"ciaran@a.remote.server","chat","Hello!").

There was a fair amount of head-scratching involved in getting the XMPP Server to Server communication going, but it turned out to be just a question of some bad inbound routing on my firewall, which would have been obvious if it wasn’t for Erlang’s sometimes cryptic error handling and reporting. Everything is working nicely now though, and I’m nearly approaching the point where I can write some code instead of criticising someone else’s.

One more thing – why am I setting up an XMPP server on each machine when I’m sending the messages elsewhere? One reason is for fault tolerance. I want to deliver messages to the local server, free from potential network woes, and rely on that to deal with getting the message to the destination. I haven’t actually checked if ejabberd will do that in case of a network outage – it may well just spit the message straight back as a delivery failure – but it seems to me that it should work that way. I’ll find out soon enough.

  1. Mickaël Rémond’s avatar

    Hello,

    Jabberlang will be replaced soon by a much better and easier to use library called exmpp.
    Stay tuned. It will be published here: http://www.process-one.net/

    Reply

  2. Ciaran’s avatar

    Thanks for the info Mickaël. I did read about exmpp somewhere while I was researching Jabberlang, and I’m looking forward to seeing it.

    By the way, I only just noticed that when pasting the code sample which I was criticising for not escaping things properly in the XML, I failed to escape the < and > properly myself. That’s guaranteed to happen when you criticise things I suppose. :)

    Reply

  3. probablycorey’s avatar

    What ever happened to exmpp? It it still being developed? I can’t find the code or reference to the library anywhere on the process-one.net site!

    Reply

  4. mikhailfranco’s avatar

    Any sight of exmpp yet ?

    Mik

    Reply

  5. CiaranG’s avatar

    No release that I’m aware of, but you might find the comments here interesting: http://www.erlangatwork.com/2008/06/why-erlang-gateways-part-1.html

    Reply

Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">