Java Reference
In-Depth Information
the message. It is the message-driven bean's responsibility to parse the message and per-
form the necessary business logic.
The
onMessage
method has a single argument: the incoming message.
The signature of the
onMessage
method must follow these rules:
• The return type must be
void
.
• The method must have a single argument of type
javax.jms.Message
.
In the
SimpleMessageBean
class, the
onMessage
method casts the incoming mes-
sage to a
TextMessage
and displays the text:
public void onMessage(Message inMessage) {
TextMessage msg = null;
try {
if (inMessage instanceof TextMessage) {
msg = (TextMessage) inMessage;
logger.info("MESSAGE BEAN: Message received: " +
msg.getText());
} else {
logger.warning("Message of wrong type: " +
inMessage.getClass().getName());
}
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
} catch (Throwable te) {
te.printStackTrace();
}
}
Running the
simplemessage
Example
You can use either NetBeans IDE or Ant to build, package, deploy, and run the
sim-
plemessage
example.
Administered Objects for the
simplemessage
Example
This example requires the following:
• A JMS connection factory resource
• A JMS destination resource