loemkie 1 mês atrás
pai
commit
14ed72da97
1 arquivos alterados com 21 adições e 2 exclusões
  1. 21 2
      src/main/java/com/qmrb/system/mq/PickCarProducer.java

+ 21 - 2
src/main/java/com/qmrb/system/mq/PickCarProducer.java

@@ -1,5 +1,6 @@
 package com.qmrb.system.mq;
 
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.time.StopWatch;
 import org.apache.rocketmq.client.exception.MQBrokerException;
 import org.apache.rocketmq.client.exception.MQClientException;
@@ -15,6 +16,7 @@ import javax.annotation.PostConstruct;
 import java.io.UnsupportedEncodingException;
 
 @Component
+@Slf4j
 public class PickCarProducer {
     /**
      * 生产者的组名
@@ -39,18 +41,35 @@ public class PickCarProducer {
         producer.setVipChannelEnabled(false);
         try {
             producer.start();
-            System.out.println("-------->:producer启动了");
+            log.info("-------->:producer启动了");
         } catch (MQClientException e) {
             e.printStackTrace();
         }
     }
 
+    /**
+     * try {
+     *             String jsonString = "{\"channelId\":\""+channelId+"\",\"carNumber\":\""+carNumber+"\"}";
+     *             return pickCarProducer.send("PushTopic8089","push",jsonString);
+     *         } catch (Exception e) {
+     *             e.printStackTrace();
+     *         }
+     * @param topic
+     * @param tags
+     * @param body
+     * @return
+     * @throws InterruptedException
+     * @throws RemotingException
+     * @throws MQClientException
+     * @throws MQBrokerException
+     * @throws UnsupportedEncodingException
+     */
     public String send(String topic,String tags,String body) throws InterruptedException, RemotingException, MQClientException, MQBrokerException, UnsupportedEncodingException {
         Message message = new Message(topic, tags, body.getBytes(RemotingHelper.DEFAULT_CHARSET));
         StopWatch stop = new StopWatch();
         stop.start();
         SendResult result = producer.send(message);
-        System.out.println("发送响应:MsgId:" + result.getMsgId() + ",发送状态:" + result.getSendStatus());
+        log.info("发送响应:MsgId:" + result.getMsgId() + ",发送状态:" + result.getSendStatus());
         stop.stop();
         return "{\"MsgId\":\""+result.getMsgId()+"\"}";
     }