The msgqueue Module for Drupal
Download
Installation Notes
Testing Notes Message
Formats
Message-oriented
middleware is a common means to enable communication between
heterogeneous systems. For example, if a Java system wants to
know about events happening in Drupal, this messaging module is
one way to provide such information. Other
ways are possible too.
The "msgqueue" module integrates Drupal with messaging
system like Apache ActiveMQ
(a JMS implementation).
This module accesses Drupal events by implementing hooks for users,
nodes, and comments, and is licensed under GPLv2.
The hooks supply events when any insert, update, or delete action
takes place for any user, node or comment. An XML message about
any such Drupal event is sent to the messaging system. The module
formats XML messages using minixml,
and puts them into a queue via the Stomp
protocol of ActiveMQ.
Installing Module
- Download the msgqueue.zip file
and expand it into /sites/all/modules/ as described by standard
module install instructions for Drupal 5. (This module can
probably run under Drupal 4, but has only been tested on 5.)
- After installation, remember to enable the module using menus
administer > site building > modules.
Testing Messages
- Download and install Java
JDK if you don't have it already.
- On a command line, "java -version" should tell you
v.5 or better; the JDK also provides javac, which will be used
later.
java -version
javac -version
Download and install Ant
if you don't have it already (on a command line, "ant -version"
should say v.6 or better)
ant -version
Download Apache ActiveMQ
v. 4 or greater and unzip it somewhere (installation is just
unzipping).
Start ActiveMQ via a script in the /bin/ directory of the
ActiveMQ installation: use the script "activemq.bat"
for Windows, "activemq" for other platforms. At startup,
the following console output should show that the message server
is listening for the Stomp protocol on port 61613 (see colorized
line below; HAM6 is just the name of a test server):
...
INFO TransportConnector - Connector openwire Started
INFO TransportServerThreadSupport - Listening for connections at: ssl://HAM6:61617
INFO TransportConnector - Connector ssl Started
INFO TransportServerThreadSupport - Listening for connections at: stomp://HAM6:61613
INFO TransportConnector - Connector stomp Started
INFO NetworkConnector - Network Connector default-nc Started
INFO BrokerService - ActiveMQ JMS Message Broker (localhost, ID:HAM6-14x1-11xxxxxx62-1:0) started
In order to see the messages coming into the queue from Drupal,
we will test with a sample client that is provided by the ActiveMQ
installation.
- While the message server above continues running, and also
Drupal is running, start a shell (a Command Prompt in Windows)
and navigate to the ActiveMQ installation, and the "example"
directory
$ cd apache-activemq-4.1.1/example
- Run the 'consumer' example by using ant:
$ ant consumer
The output should look something like this:
larry@HAM6 ~/tools/apache-activemq-4.1.1/example
$ ant consumer
Buildfile: build.xml
init:
[mkdir] Created dir: C:\tools\apache-activemq-4.1.1\example\target\classes
[mkdir] Created dir: C:\tools\apache-activemq-4.1.1\example\src\ddl
compile:
[javac] Compiling 8 source files to C:\tools\apache-activemq-4.1.1\example\target\classes
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
consumer:
[echo] Running consumer against server at $url = tcp://localhost:61616 for subject $subject = TEST.FOO
[Java] Connecting to URL: tcp://localhost:61616
[Java] Consuming queue: TEST.FOO
[Java] Using a non-durable subscription
[Java] We are about to wait until we consume: 10 message(s) then we will shutdown
The last line reports that the consumer is waiting for events
to print.
- Return to the Drupal screen and click Create content->Article
and submit a new article, edit an article, delete an article,
and do similar actions for comments and users. For each action,
an event should print on the consumer console, like the following
for inserting a comment, user, and node, respectively:
[Java] Received: <?xml version="1.0"?>
[Java] <msg>
[Java] <comment op="insert"...
[Java] Received: <?xml version="1.0"?>
[Java] <MSG>
[Java] <user op="insert" ui...
[Java] Received: <?xml version="1.0"?>
[Java] <MSG>
[Java] <node op="insert" ni...
The Consumer example code truncates messages to only 50 characters,
so what you see above are just a small parts of the messages.
If you want to see the full message, edit the Java class in examples/src/
named ConsumerTool.java and comment out the lines:
if (msg.length() > 50) {
MSG = msg.substring(0, 50) + "...";
}
and just run 'ant consumer' again--it will automatically recompile
and run.
Message Formats
All messages are delimited with a <msg> tag, followed by
a 'payload' tag of <node>, <comment> or <user>.
The first attribute of the payload tag is the operation attribute
"op", which describes whether this message is [insert,
delete, update]. The rest of the attributes depend on the payload.
User-entered text is found in child tags, within CDATA delimiters.
Dates are in ISO 8601 format, using the server's local timezone.
Node message sample:
<MSG> <node op="insert" nid="13" vid="13" type="article" uid="1"
created="2007-12-10T12:47:18-0800" status="1"
changed="2007-12-10T12:47:18-0800"
comment="2" promote="1" sticky="0" > <title><![CDATA[test article subject]]></title> <body><![CDATA[test article body]]></body> </node> </MSG>
Comment message sample:
<MSG> <comment op="insert" cid="3" nid="13" uid="1"> <subject><![CDATA[test comment subject]]></subject> <body><![CDATA[test comment body]]></body>
</comment> </MSG>
User message sample:
<MSG> <user op="insert" uid="4" name="testuser" mail="x@y.com"
mode="0" created="2007-12-10T12:47:18-0800"
access="0" login="0" status="1" language="" /> </MSG>
This page
is licensed under a Creative
Commons License.
|