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.
-
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/ -
Any sight of exmpp yet ?
Mik

5 comments
Comments feed for this article
Trackback link: http://ciarang.com/posts/adventures-in-jabberlang/trackback