Appendix E. Message-Driven EJB: Status Update Listeners Example
Description
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.
OREILLY_EJB_BOOK_CH08_TWITTER_USERNAME OREILLY_EJB_BOOK_CH08_TWITTER_PASSWORD
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
(i.e., java.util.concurrent) to
reliably test that asynchronous components have completed as
expected.