//package com.fdkankan.common.rocketmq.producer;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.fdkankan.common.rocketmq.MQLogFormat;
//import org.apache.rocketmq.client.exception.MQBrokerException;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.common.message.Message;
//import org.apache.rocketmq.remoting.exception.RemotingException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//
////@Component
//public class MqSendMessage {
//    private static Logger log = LoggerFactory.getLogger("programLog");
//
//    @Resource(name = "testProducer")
//    protected DefaultMQProducer testProducer;
//
//    @Value("${rocketmq.topic.testGrop}")
//    private String topicName;
//
//    @Value("${rocketmq.tag.testGrop}")
//    private String tagName;
//
//
//    public void sendMessage(Object context){
//        long currentTimeMillis = System.currentTimeMillis();
//        String keys = topicName + "_"+ currentTimeMillis;
//        Message msg = new Message(
//                topicName,
//                tagName,
//                // keys 每条消息唯一
//                keys,
//                JSONObject.toJSONString(context).getBytes());
//        try {
//            testProducer.send(msg);
//            log.info(String.format(MQLogFormat.mqProducerLogFormat, topicName, tagName, keys, JSON.toJSONString(context)));
//            log.info("SendMQ|messageContent|推送成功："+ JSONObject.toJSONString(context) + "_" + currentTimeMillis);
//        } catch (MQClientException e) {
//            log.info("testProducer|sendMessage|MQClientException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (RemotingException e) {
//            log.info("testProducer|sendMessage|RemotingException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (InterruptedException e) {
//            log.info("testProducer|sendMessage|InterruptedException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (MQBrokerException e) {
//            log.info("testProducer|sendMessage|MQBrokerException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        }
//    }
//
//    /**
//     * rabbit.queue.laser=QUEUE_LASER_A   老代码中有区分，先暂时这样写
//     * @param topicName
//     * @param context
//     */
//    public void sendMessageLaser(String topicName, Object context){
//        long currentTimeMillis = System.currentTimeMillis();
//        String keys = topicName + "_"+ currentTimeMillis;
//        Message msg = new Message(
//                topicName,
//                tagName,
//                // keys 每条消息唯一
//                keys,
//                JSONObject.toJSONString(context).getBytes());
//        try {
//            testProducer.send(msg);
//            log.info(String.format(MQLogFormat.mqProducerLogFormat, topicName, tagName, keys, JSON.toJSONString(context)));
//            log.info("SendMQ|messageContent|推送成功："+ JSONObject.toJSONString(context) + "_" + currentTimeMillis);
//        } catch (MQClientException e) {
//            log.info("testProducer|sendMessage|MQClientException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (RemotingException e) {
//            log.info("testProducer|sendMessage|RemotingException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (InterruptedException e) {
//            log.info("testProducer|sendMessage|InterruptedException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        } catch (MQBrokerException e) {
//            log.info("testProducer|sendMessage|MQBrokerException");
//            log.error("testProducer|sendMessage|" + e.getMessage(), e);
//        }
//    }
//}
