This module provides on and off-machine connectivity (inproc, IPC, TCP, Multicast) to FreeSWITCH using the ØMQ library. This page is not meant to be an exhaustive reference of how 0MQ can be used, for that we recommend going to the learning section of the ØMQ site; along with a couple video presentations you will find The Guide, which is particularly well written.
This module was written to make integration with FreeSWITCH much easier, more scalable, and available to more languages than mod_event_socket or mod_erlang_event could effectively provide. The ØMQ library has bindings for over 20 languages, so chances are that you can easily integrate with FreeSWITCH using your favorite.
Click here to expand Table of Contents
- Configuration file
- Access control
- API channel
- Application to call out from dialplan
- XML search bindings (provide configuration via mod_event_zmq similar to mod_xml_curl)
All data interactions with modzmq use JSON. Almost every language has some kind of JSON framework available, and if not JSON is simple enough to parse with a handful of lines of code.
Here's an example JSON encoded event:
"Event-Date-Local": "2011-03-26 12:33:27",
"Event-Date-GMT": "Sat, 26 Mar 2011 18:33:27 GMT",
"MWI-Voice-Message": "15/0 (0/0)",
The current version of modzmq stands up a TCP PUB endpoint to publish all switch events to any subscribers; this endpoint listens on all IP addresses on port 5556.
Here's a simple Python example client that subscribes to the event publications, printing 100 events before quitting:
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
for count in range (100):
string = subscriber.recv()
A couple interesting things to note:
You can start the client before or after the server starts, ØMQ will take care of establishing the network connection, and reconnection if the server goes down and up while the client is running. You can also connect any number of clients to the publisher simultaneously, they'll all receive the same messages.
The ZMQ Library and fork() don't work together very well. mod_event_zmq may core dumps if FreeSWITCH uses fork() for system calls (e.g. sending mail, use voicemail, etc). You can put <param name="threaded-system-exec" value="true"/> in switch.conf.xml to overcome this for system calls but this doesn't mean you are safe from crashes. 
You will need to have libuuid-devel or libuuid-dev package installed on your system before compiling this module.