Java Reference
In-Depth Information
/** Public, default constructor */
public MessageEchoBean () {}
/** Set the MessageDrivenContext */
public void setMessageDrivenContext(MessageDrivenContext context) {
this.context = context;
}
/** ejbCreate is required by EJB Specification */
public void ejbCreate() { }
/** ejbRemove is required by EJB Specification */
public void ejbRemove() { }
/**
* Message handling, the business logic. The message text is printed on
the
* output screen. <BR> It can be extended to implement any business rules
* upon receiving the message.
*/
public void onMessage(Message message) {
TextMessage textmessage = (TextMessage)message;
try {
String s = textmessage.getText();
System.out.println("A message received: " + s);
} catch(JMSException e) {
ex.printStackTrace();
}
}
}
In the following respects, a message-driven bean resembles a stateless session bean:
 
A message-driven bean's instances retain no data or conversational state for a specific client.
 
All instances of a message-driven bean are equivalent, allowing the EJB container to assign a
message to any message driven bean instance available. The container can pool these instances
to allow streams of messages to be processed concurrently.
 
A single message-driven bean can process messages from multiple clients.
The instance variables of the message-driven bean instance can contain some state across the
handling of client messages (for example, a JMS API connection, an open database connection, or an
object reference to an enterprise bean object).
When a JMS message arrives, the container calls the message-driven bean's onMessage method to
process the message. The onMessage method normally casts the message to one of the five JMS
message types and handles it in accordance with the application's business logic. The onMessage
method may call helper methods, or it may invoke a session or entity bean to process the information in
the message or to store it in a database.
Search WWH ::




Custom Search