Day 10. Message-Driven Beans

So far, you have looked at two types of Enterprise Java Bean (EJB)—the Session bean and the Entity bean. Today you will consider the third and final EJB, the Message-driven bean. Topics that are covered are as follows:

  • Similarities and differences with Entity and Session beans

  • The life-cycle of a Message-driven bean

  • Writing a Message-driven bean

Prior to the EJB 2.0 specification, it was only possible to support asynchronous message passing by writing an external Java program that acted as a listener. A listener is a program whose sole purpose is to wait for data to arrive, for example, a socket server program that “listens” on a socket and perform some action when it detects client connections. The listener was then able to invoke methods on a session or entity bean. All EJB method calls had to be synchronous and initiated by the client. This approach had the disadvantage that the message was received outside of the server, so it could not be part of an EJB transaction.

With the release of J2EE 1.3, you can use Message-driven beans to combine the functionality of EJBs with the Java Message Service (JMS).

Although JMS was covered in detail on Day 9, “Java Message Service,” the following is a quick recap of its main features:

  • JMS is a Java API that specifies how applications can create, send, receive, and read messages.

  • JMS enables communication that is both asynchronous and reliable, while minimizing the amount of knowledge and programming that is required.

  • The implementation of the JMS API is provided by a number of vendors who are known as JMS providers.

  • Message queues are associated with the point-to-point message domain. Messages in a queue are persistent but can only be consumed by one receiver.

  • Topics allow a message to be sent to more then one receiver (called a subscriber). Messages are not persistent; they are immediately delivered to all existing subscribers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.60.63