Java Reference
In-Depth Information
Once we have entered all the required information, our message driven bean is
created in the specified package.
package com.ensode.mdb;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
@MessageDriven(mappedName = "jms/myQueue", activationConfig = {
@ActivationConfigProperty(
propertyName = "acknowledgeMode",
propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(
propertyName = "destinationType",
propertyValue = "javax.jms.Queue")
})
public class MessageReceiverBean implements MessageListener {
public MessageReceiverBean() {
}
public void onMessage(Message message) {
}
}
In the generated code, all we need to do is implement the body of the onMessage()
method, and deploy our project. The onMessage() method will process any
messages on the JMS destination our message driven bean is receiving
messages from.
We can write any arbitrary code in the onMessage() method. The possibilities are
endless. However, this method is typically used to save data from the message into a
database, or to write some output into a log. In our example, we will simply send the
contents of the message to the stdout log of our application server.
public void onMessage(Message message) {
TextMessage textMessage = (TextMessage) message;
try {
System.out.println("Received message:" +
textMessage.getText());
} catch (JMSException ex) {
Logger.getLogger(
 
Search WWH ::




Custom Search