Session beans, as we’ve seen up to this point, are best suited for servicing client requests. Many enterprise systems, however, use a messaging layer to asynchronously pass requests from application to application. In Java, we use the Java Message Service abstraction to push/pull messages via Queues and Topics, and the integration of JMS with EJB is the message-driven bean.
In this example, we implement social networking status updates via a consumer/publisher Topic. Anyone listening on the Topic will receive incoming status updates, and we create 2 listeners: 1 simple one to log out to the command-line or logfile, and another to push the updates to Twitter.
Note: Set the environment variables below before running to take advantage of the Twitter updates while running the tests.
Additionally, in this example we show how the use of a single JVM
for the test and the server can be used to enable shared memory locking
reliably test that asynchronous components have completed as
Wiki article: http://community.jboss.org/docs/DOC-15570
Following is a full listing of all source code used in this runnable example.