|Using the EMG Java API|
|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.
Sample source code for sending a message from Java can be found in Send.java.
In order to compile the source code above, save the source code to Send.java and put the mgp and util jar files in the same directory and then run
And to run it after compilation is successful
Sample source code for receiving messages from Java can be found in Receive.java.
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
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