
/*
 *  Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
*/
package oracle.javacloud.mdb;

import java.util.logging.*;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.*;

@MessageDriven(mappedName = "local-queue", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "connectionFactoryType", propertyValue = "javax.jms.ConnectionFactory"),
    @ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue="local-connection-factory")
})
public class QueueMessageBean implements MessageListener {

    public QueueMessageBean() {
    }
    
    @Override
    public void onMessage(Message message) {

        Logger logger = Logger.getLogger(QueueMessageBean.class.getName());
        try {
            if (message instanceof TextMessage) {
                System.out.println("JMS message received at QueueMessageBean : "+((TextMessage) message).getText());
                logger.log(Level.INFO, "JMS message received at QueueMessageBean : "+ ((javax.jms.TextMessage) message).getText());

            } else {
                System.out.println(message.getJMSMessageID());
            }
        } catch (JMSException ex) {
            Logger.getLogger(QueueMessageBean.class.getName()).log(Level.SEVERE, "Error: ", ex);
        }    
    
    }
}

