package  org.ts.ddcs.Worker;

import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.common.constant.GBConstants;
import org.ts.ddcs.kafka.KafkaClient;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.main.DataProcess;


import java.util.concurrent.Callable;

/**
 * 转发报文到处理服务器
 * @author dylan
 */
public class RelayDatagramTask implements Callable<Integer> {
    private JSONObject body;

    public RelayDatagramTask(JSONObject body) {
        this.body = body;
    }

    @Override
    public Integer call() throws Exception {
        String logId = LogHelper.createLogId("RelayDatagramTask");
        try {
            LogHelper.info(logId + " 即将转发报文:" + body.toJSONString());
         //   body.put(GBConstants.REDIS_KEY_COLLECT_SERVER, DataProcess.config().getServerId());
            String queue = DataProcess.queueConfig().getWaitingToProcessDatagram();
            KafkaClient.messageSubmit(queue, body.toJSONString());
        } catch (Exception e) {
            LogHelper.error(logId,e);
        } finally {
            LogHelper.info(logId + " 已通过 MQ 成功转发报文");
        }
        return 0;
    }
}
