package com.lightinit.hsdatashow.spring;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.net.URLDecoder;

/**
 * Created by Mr.Yao on 2017/11/30.
 */
@Component
public class ConsumerPushListener implements MessageListener {

    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void onMessage(Message message) {
        if(message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            try {
                if (tm != null && StringUtils.isEmpty(tm.getText())==false) {
                    String msgJson=URLDecoder.decode(tm.getText(), "utf-8");
                    System.out.println("接收到消息:"+msgJson);

                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
