package com.union;

import com.alibaba.fastjson.JSON;
import com.union.ai.api.common.consts.RocketMqConsts;
import com.union.ai.api.dao.model.ApiLog;
import com.union.ai.api.helper.DefaultProducerHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.junit.Test;

/**
 * Created by IntelliJ IDEA.
 * Author: xingxin.jing
 * Date: 2019/4/13
 * Time: 下午2:39
 */
@Slf4j
public class RocketMQProducerTest extends BaseTest {

    private DefaultProducerHelper producer = DefaultProducerHelper.getSingleton();

    @Test
    public void send() {
        ApiLog apiLog = new ApiLog();
        apiLog.setApiId(1231);
        apiLog.setAppId(234121);
        apiLog.setInvokeTime(String.valueOf(1221122323));
        apiLog.setResponseTime(String.valueOf(1213232434));
        apiLog.setParams("测试1");
        try {

            Integer err_no = 0;
            if (err_no == null || err_no != 0) {
                apiLog.setCallResult(0);
            } else {
                apiLog.setCallResult(1);
            }
            SendResult sendResult = producer.send("AI_MQ_TOPIC", JSON.toJSONString(apiLog));
            log.info("mq发送结果：{}", JSON.toJSONString(sendResult));
        } catch (Exception e) {
            log.error("发送数据失败："+ JSON.toJSONString(apiLog), e);
        }
    }
}
