!--a11y-->
Message-Driven Bean Example 
The message-driven bean (MDB) follows the following scenario: a client JSP sends a message to a session bean. This bean sends the message to a topic destination and a MDB gets that message from the destination.
The EAR file that contains the example is in the default application started when the J2EE Engine starts up. It is under the alias Message-driven bean.
Sent Message Path


The J2EE Engine server must be started in a console. The JMS Provider service must be started.
The example consists of the following elements:
● A message-driven bean – this class contains the onMessage() method. In this case the method writes the messages that are received to the console only.
● A session bean – contains the sendMessage(String message) method in its remote interface. The implementation of the method enables a publisher to be created to the SenderTopic topic destination. Then a TextMessage is created and published to that topic.
● A JSP file – the send.jsp calls the session bean’s method sendMessage() and uses this method to send the message to the topic.
● A jms-factories.xml – this is the .XML that creates a connection factory. The name of the connection is SenderTopicFactory. The session bean has a reference to that factory in the XML. The XML is written according to the jms-factories.dtd.
● A jms-destination.xml – the .XML file that creates the topic. The XML is written according to the jms-destinations.dtd.
● The ejb-jar.xml file is created for the two beans. For all the message-driven beans that are deployed on the J2EE Engine, the ejb-j2ee-engine.xml must be indicated, which specifies the name of the topic to which the MDB listens. Such tag is not available in the ejb-jar.xml but it is required, so an EAR file has to be created.
For more information about the structure of the ejb-j2ee-engine.xml, see ejb-j2ee-engine.dtd.
You can find the source files of this sample under <DeveloperStudio_install_dir>\eclipse\examples\J2EE_MDB.zip.
Deploy the sample to the J2EE Engine using the instructions in the J2EE_MDBReadme.pdf file. Start the application using the following URL: http://<host>:<port>/mdb/send.jsp.
In the page that appears, the messages written in the text box can now be sent to the topic. The messages sent by the JSP client are received by the destination, and then the message-driven bean displays them in the console. You can view the source code in the Web browser when you start the example.