Case study:
EMG at Mblox (PDF)
Using the EMG Java API Print
Thursday, 14 July 2011
July 2011 - Updated for EMG Java API 2.0


It is possible to interface EMG from Java using the EMG Java API. The API is primarily used to send and receive messages and it can also be used to perform a server reload.

In order to generate statistics and track messages JDBC must be used to query the EMG database tables directly.

Using the Java API

To use the Java API two jar files needs to be downloaded, mgp.jar and util.jar. The actual names of these jar files also include the version number on download, for example mgp-20.jar and util-19.jar.

Javadoc »

Sending messages

Sample source code for sending a message from Java can be found in

In order to compile the source code above, save the source code to and put the mgp and util jar files in the same directory and then run


And to run it after compilation is successful

java Send

Receiving messages

Sample source code for receiving messages from Java can be found in

Message statistics from database

In order to find information about messages sent EMG must be configured to use a database and specifically the "routelog" which is defined by adding the "ROUTELOGDB" keyword to server.cfg.

Sample query for finding information about a specific message:

mysql> SELECT msgid, username, sourceaddr, destaddr, msgtype FROM routelog
WHERE msgid = 22074701;
| msgid    | username   | sourceaddr | destaddr   | msgtype |
| 22075705 | user1234   | 4531355xxx | 4520126xxx |       1 |
1 row in set (0.01 sec)

Here we see the unique message id, username for user who submitted message, source address (sender), destination address (recipient) and message type (1 = normal message).

Sample query to find how many messages was sent successfully in July 2011:

mysql> SELECT COUNT(*) FROM routelog
WHERE starttime >= '2011-07-01 00:00:00' AND starttime <= '2011-07-30 23:59:00'
AND status = 1 AND msgtype = 1;
| COUNT(*) |
|   218483 |
1 row in set (1.63 sec)