Message-Driven Bean Use Cases

We saw earlier in the chapter that within the Java EE environment, session beans and web components can only receive messages synchronously, whereas message-driven beans can receive messages asynchronously. While this is a key point for the usefulness of MDBs, there are several other use cases that make MDBs a good design choice.

Message Facade

There may be times when you want to expose business functionality written in Java to remote client applications outside of the EJB container. This is typically done though the use of the Session Facade pattern. In Java EE, this pattern is implemented via stateless session beans that act as the remote entry point to the business functionality we want to expose. However, this implementation assumes that the client invoking the service is written in Java, can support the RMI/IIOP protocol, and has the necessary interfaces, stubs, and skeletons to access the remote session bean. While this solution is valid for Java-based client applications, it does not lend itself well to interoperability with non-Java clients or Java clients outside of the Java EE environment.

Another approach for exposing business functionality within an EJB container to outside client applications is through the use of the Message Facade pattern. Using a message-driven bean as a facade to business functionality (services) decouples client applications from the service implementation, allowing for greater flexibility and interoperability, particularly ...

Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.