December 2017
Intermediate to advanced
372 pages
8h 46m
English
The purpose of a message-driven bean is to consume messages from a Java Message Service (JMS) queue or a JMS topic, depending on the messaging domain used (refer to Chapter 8, Java Message Service). A message-driven bean must be decorated with the @MessageDriven annotation; the mappedName attribute of this annotation must contain the Java Naming and Directory Interface (JNDI) name of the JMS message queue or JMS message topic that the bean will be consuming messages from. The following example illustrates a simple message-driven bean:
package net.ensode.javaeebook; import javax.ejb.MessageDriven; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage;