package com.usky.demo.service.rocketmq;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.usky.demo.service.rocketmq.SimpleContext;
import com.usky.demo.service.vo.MQDataVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumer.group}", topic = "${rocketmq.consumer.topic}")
public class MyConsumer implements RocketMQListener<String> {
    @Autowired
    private SimpleContext simpleContext;

    @Value("${spring.sourcetype}")
    private String sourcetype;

    @Override
    public void onMessage(String message){
        System.out.println("DirectReceiver消费者收到消息： " + message);

        MQDataVO mqDataVO = new MQDataVO();
        mqDataVO.setData(message);
        if(sourcetype.equals("taos")){
            mqDataVO.setDescribe("tdengine");
        }else{
            mqDataVO.setDescribe("influx");
        }

        simpleContext.getResource(mqDataVO);
    }
}
