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.PlateaJMSService;


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

public class Ad74aMDBClienteJMS implements MessageListener {

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

	@Autowired
	PlateaJMSService plateaJMSService;

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

}
