O'Reilly logo

Enterprise JavaBeans 3.1, 6th Edition by Bill Burke, Andrew Lee Rubinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Source Listing

Following is a full listing of all source code used in this runnable example.

Implementation Resources

StatusUpdate.java ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required