Browse Source

下掉mq相关代码

xueyiming 3 tháng trước cách đây
mục cha
commit
b4722f792c

+ 75 - 75
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/config/MqConfig.java

@@ -1,75 +1,75 @@
-package com.tzld.longarticle.recommend.server.config;
-
-import com.aliyun.openservices.ons.api.MessageListener;
-import com.aliyun.openservices.ons.api.PropertyKeyConst;
-import com.aliyun.openservices.ons.api.bean.ConsumerBean;
-import com.aliyun.openservices.ons.api.bean.ProducerBean;
-import com.aliyun.openservices.ons.api.bean.Subscription;
-import com.tzld.longarticle.recommend.server.mq.MessageCallbackCustomer;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.DependsOn;
-
-import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-@Configuration
-public class MqConfig {
-
-    @Value("${rocketmq.accessKey}")
-    private String accessKey;
-    @Value("${rocketmq.secretKey}")
-    private String secretKey;
-    @Value("${rocketmq.nameSrvAddr}")
-    private String nameSrvAddr;
-    @Value("${pushMessage.callback.topic}")
-    private String callbackTopic;
-    @Value("${pushMessage.callback.tag}")
-    private String callbackTag;
-    @Value("${pushMessage.callback.groupId}")
-    private String callbackGroupId;
-
-    @Autowired
-    private MessageCallbackCustomer messageCallbackCustomer;
-
-    public Properties getMqProperties() {
-        Properties properties = new Properties();
-        properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
-        properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
-        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);
-        return properties;
-    }
-
-    @Bean(initMethod = "start", destroyMethod = "shutdown")
-    public ProducerBean buildProducer() {
-        ProducerBean producer = new ProducerBean();
-        producer.setProperties(getMqProperties());
-        return producer;
-    }
-
-
-    @Bean(initMethod = "start", destroyMethod = "shutdown")
-    public ConsumerBean buildConsumer() {
-        ConsumerBean consumerBean = new ConsumerBean();
-        //配置文件
-        Properties properties = getMqProperties();
-        properties.setProperty(PropertyKeyConst.ConsumeThreadNums, "20");
-        properties.setProperty(PropertyKeyConst.GROUP_ID, callbackGroupId);
-        consumerBean.setProperties(properties);
-        //订阅关系
-        Map<Subscription, MessageListener> subscriptionTable = new HashMap<>();
-        Subscription subscription = new Subscription();
-        subscription.setTopic(callbackTopic);
-        subscription.setExpression(callbackTag);
-        subscriptionTable.put(subscription, messageCallbackCustomer);
-        //订阅多个topic如上面设置
-        consumerBean.setSubscriptionTable(subscriptionTable);
-        return consumerBean;
-    }
-
-
-}
+//package com.tzld.longarticle.recommend.server.config;
+//
+//import com.aliyun.openservices.ons.api.MessageListener;
+//import com.aliyun.openservices.ons.api.PropertyKeyConst;
+//import com.aliyun.openservices.ons.api.bean.ConsumerBean;
+//import com.aliyun.openservices.ons.api.bean.ProducerBean;
+//import com.aliyun.openservices.ons.api.bean.Subscription;
+//import com.tzld.longarticle.recommend.server.mq.MessageCallbackCustomer;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.context.annotation.DependsOn;
+//
+//import javax.annotation.Resource;
+//import java.util.HashMap;
+//import java.util.Map;
+//import java.util.Properties;
+//
+//@Configuration
+//public class MqConfig {
+//
+//    @Value("${rocketmq.accessKey}")
+//    private String accessKey;
+//    @Value("${rocketmq.secretKey}")
+//    private String secretKey;
+//    @Value("${rocketmq.nameSrvAddr}")
+//    private String nameSrvAddr;
+//    @Value("${pushMessage.callback.topic}")
+//    private String callbackTopic;
+//    @Value("${pushMessage.callback.tag}")
+//    private String callbackTag;
+//    @Value("${pushMessage.callback.groupId}")
+//    private String callbackGroupId;
+//
+//    @Autowired
+//    private MessageCallbackCustomer messageCallbackCustomer;
+//
+//    public Properties getMqProperties() {
+//        Properties properties = new Properties();
+//        properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
+//        properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
+//        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);
+//        return properties;
+//    }
+//
+//    @Bean(initMethod = "start", destroyMethod = "shutdown")
+//    public ProducerBean buildProducer() {
+//        ProducerBean producer = new ProducerBean();
+//        producer.setProperties(getMqProperties());
+//        return producer;
+//    }
+//
+//
+//    @Bean(initMethod = "start", destroyMethod = "shutdown")
+//    public ConsumerBean buildConsumer() {
+//        ConsumerBean consumerBean = new ConsumerBean();
+//        //配置文件
+//        Properties properties = getMqProperties();
+//        properties.setProperty(PropertyKeyConst.ConsumeThreadNums, "20");
+//        properties.setProperty(PropertyKeyConst.GROUP_ID, callbackGroupId);
+//        consumerBean.setProperties(properties);
+//        //订阅关系
+//        Map<Subscription, MessageListener> subscriptionTable = new HashMap<>();
+//        Subscription subscription = new Subscription();
+//        subscription.setTopic(callbackTopic);
+//        subscription.setExpression(callbackTag);
+//        subscriptionTable.put(subscription, messageCallbackCustomer);
+//        //订阅多个topic如上面设置
+//        consumerBean.setSubscriptionTable(subscriptionTable);
+//        return consumerBean;
+//    }
+//
+//
+//}

+ 5 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mq/MessageCallbackProducer.java

@@ -25,8 +25,8 @@ public class MessageCallbackProducer {
     @Value("${pushMessage.callback.tag}")
     private String TAG;
 
-    @Autowired
-    private ProducerBean producer;
+//    @Autowired
+//    private ProducerBean producer;
 
     @Autowired
     private AccessTokenService accessTokenService;
@@ -44,7 +44,7 @@ public class MessageCallbackProducer {
         message.setBody(JSON.toJSONString(param).getBytes(StandardCharsets.UTF_8));
         try {
             log.info("sendMessage = {}", message);
-            producer.send(message);
+//            producer.send(message);
         } catch (Exception e) {
             log.error("error send param = {}", param);
             log.error("error", e);
@@ -57,8 +57,8 @@ public class MessageCallbackProducer {
     private void retry(Message message) {
         for (int i = 0; i < 3; i++) {
             try {
-                SendResult sendResult = producer.send(message);
-                log.info("sendResult = {}", sendResult);
+//                SendResult sendResult = producer.send(message);
+//                log.info("sendResult = {}", sendResult);
                 return;
             } catch (Exception e) {
                 log.error("retry send error {}", i, e);