Entering content frame

Example Message-Driven Bean Example Locate the document in its SAP Library structure

The message-driven bean 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 message-driven bean gets that message from the destination.

The .EAR file that contains the example is in the default application started when the SAP J2EE Engine starts up. It is under the alias Message-driven bean.

The path of the sent message in the example:

This graphic is explained in the accompanying text

This graphic is explained in the accompanying text

The JMS Provider Service must be started.

The SAP J2EE Engine server must be started in a console.

 

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 Structure linkjms-factories.dtd.

·        A jms-destination.xml – the .XML file that creates the topic. The XML is written according to the Structure linkjms-destinations.dtd.

·        The ejb-jar.xml file is created for the two beans. For all the message-driven beans that are deployed on the SAP J2EE Engine, the ejb-j2ee-engine.xml must be indicated, which specifies the name of the topic to which the message-driven bean listens. Such a 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 Structure linkejb-j2ee-engine.dtd in the Reference Manual.

Deploying and starting the example

In the Web page of the example, simply choose Deploy and Run. 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.

 

 

Leaving content frame