Integrating RabbitMQ with ejabberd
ejabberd is integrated with RabbitMQ by means of mod_rabbitmq gateway. If you followed my ejabberd installation instructions, you should already have mod_rabbitmq installed.
Configure mod_rabbitmq
Open /opt/ejabberd/ejabberd/etc/ejabberd/ejabberd.cfg file, find modules section, and add mod_rabbitmq stanza to the list
You need to replace RABBIT_NODE with the real value, which you can find from the RabbitMQ process information
$ ps -ef | grep beam
rabbitmq 8525 8142 0 16:37 pts/0 ... -sname rabbit@ubuntu ...
You can see my RabbitMQ node name is rabbit@ubuntu.
Set up cookie
To make RabbitMQ and ejabberd work together, they have to run in the same Erlang cluster. That means they have to use the same cookie file. If you installed RabbitMQ from binary distribution, it uses the user’s cookie ~/.erlang.cookie. ejabberd, on the other hand, uses its own cookie. Let’s replace it with the user’s
$ cd /opt/ejabberd/ejabberd/var/lib/ejabberd
$ rm -f .erlang.cookie
$ ln -s ~/.erlang.cookie
Restart ejabberd server
$ /opt/ejabberd/ejabberd/sbin/ejabberdctl restart
Add rabbit buddy to roster
The rabbit’s JID consists of two parts: exchange name and routing domain. The routing domain is a string rabbitmq.EJABBERD_HOST
where EJABBERD_HOST is the host you registered in ejabberd.cfg. In my case the routing domain is rabbitmq.jabber.ndpar.com
.
For the name you can use any exchange name available in the RabbitMQ server. I use amq.fanout
exchange which exists in every RabbitMQ server. So I go to my IM client (Adium) and add this user to the buddies list amq.fanout@rabbitmq.jabber.ndpar.com
.
Rabbit’s greetings
To publish a message to RabbitMQ I use the same Groovy script as in the previous post
$ ./publisher.groovy
Resources
- Tony Garnock-Jones’ presentation slides about RabbitMQ and its extensions.