package org.well.well.activemq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.well.well.core.util.MeterDecoderUtil;
import org.well.well.manager.MeterManager;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.util.Map;

@Component
public class QueueMessageListener implements MessageListener {
    private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private MeterManager meterManager;
    public void onMessage(Message message) {
        try {

            TextMessage tm = (TextMessage)(message);
            System.out.println(tm.getText());
            logger.info("**********收到ACTIVEMQ消息："+tm.getText());
            Map<String,String> meterMap= MeterDecoderUtil.decodeStr(tm.getText());
            meterManager.processMeterData(meterMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("**********解析ACTIVEMQ消息出错");
        }

    }
}
