MDB Example
The snippet can be accessed without any authentication.
Authored by
German Adolfo Faller Farias
Ejemplo de MDB
mdb.java 1.92 KiB
package uy.com.faller.ejemplo.mdb;
import org.apache.log4j.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import java.io.Serializable;
import static StringUtils.nullOrEmpty;
@MessageDriven(
name = "ConsumidorMDB",
activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowldge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "java.jms.queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/ejemplo_respuesta"),
@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "50")
}
)
public class ConsumidorMDB implements MessageListener {
private static final Logger LOGGER = Logger.getLogger(ConsumidorMDB.class);
@Override
public void onMessage(Message message) {
try {
ObjectMessage objectMessage = (ObjectMessage) message;
if (objectMessage == null) {
LOGGER.error(Codigos.ERROR_MENSAJE_RECIBIDO_ES_NULO);
} else {
LogSetIDSession.setIDSession(message.getJMSMessageID());
String uuid = objectMessage.getStringProperty(PropertiesConstants.UUID);
LOGGER.info("Llego " + message.getClass().getSimpleName() + " al MDB uuidSolicitud:" + uuid);
LOGGER.debug("Targets: " + objectMessage.getStringProperty(PropiedadesConstants.TARGET));
String string = (String) objectMessage.getObject();
LOGGER.debug("Mensaje recibido: " + string);
} catch (JMSException e) {
//Reintentamos
throw new EJBException(e);
}
}
}
Please register or sign in to comment