package com.ejie.ad74a.mdb;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.interceptor.Interceptors;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

import com.ejie.ad74a.jms.service.LibroRegistroJMSService;


@Interceptors(value = SpringBeanAutowiringInterceptor.class)
@MessageDriven(name = "Ad74aMDBPapel0ClienteJMS", activationConfig = {
		@ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue = "ad74a.ad74aJMSFactory"),
		@ActivationConfigProperty(propertyName = "destinationJndiName", propertyValue = "ad74a.ad74aPapel0Queue"),
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
@TransactionManagement(TransactionManagementType.BEAN)

public class Ad74aMDBPapel0ClienteJMS implements MessageListener {

	private static final Logger logger = LoggerFactory.getLogger(Ad74aMDBPapel0ClienteJMS.class);

	@Autowired
	LibroRegistroJMSService libroRegistroJMSService;

	@Override
	public void onMessage(Message message) {
		Ad74aMDBPapel0ClienteJMS.logger.info("Recibimos mensaje Ad74aMDBPapel0ClienteJMS");
		try {
			this.libroRegistroJMSService.tratarMessage(message);
		} catch (Throwable e) {
			Ad74aMDBPapel0ClienteJMS.logger.error("Ad74aMDBPapel0ClienteJMS Error al tratar el message : " + e.getMessage());
		}
	}

}
