瀏覽代碼

ICSS数据埋点改成异步

gaodm 6 年之前
父節點
當前提交
1a9fb55659

+ 7 - 1
config-server/src/main/resources/shared/icss-service-dev.yml

@@ -52,7 +52,13 @@ spring:
       bindings:
         outputLog:
           destination: myLog
-  #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        outputPoint:
+          destination: myPoint
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        inputPoint:
+          destination: myPoint
+          group: pointReceiveGroup
 
   #mq
   rabbitmq:

+ 7 - 1
config-server/src/main/resources/shared/icss-service-local.yml

@@ -52,7 +52,13 @@ spring:
       bindings:
         outputLog:
           destination: myLog
-  #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        outputPoint:
+          destination: myPoint
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        inputPoint:
+          destination: myPoint
+          group: pointReceiveGroup
 
   #mq
   rabbitmq:

+ 7 - 1
config-server/src/main/resources/shared/icss-service-pro.yml

@@ -52,7 +52,13 @@ spring:
       bindings:
         outputLog:
           destination: myLog
-  #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        outputPoint:
+          destination: myPoint
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        inputPoint:
+          destination: myPoint
+          group: pointReceiveGroup
 
   #mq
   rabbitmq:

+ 7 - 1
config-server/src/main/resources/shared/icss-service-test.yml

@@ -52,7 +52,13 @@ spring:
       bindings:
         outputLog:
           destination: myLog
-  #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        outputPoint:
+          destination: myPoint
+        #          contentType: text/plain      # 实体 json string 在传递的类型装换 查看 http://docs.spring
+        inputPoint:
+          destination: myPoint
+          group: pointReceiveGroup
 
   #mq
   rabbitmq:

+ 9 - 0
icss-service/src/main/java/com/diagbot/rabbit/MyProcessor.java

@@ -20,4 +20,13 @@ public interface MyProcessor {
 
     @Output(OUTPUT_LOG)
     MessageChannel outputLog();
+
+    String INPUT_POINT = "inputPoint";
+    String OUTPUT_POINT = "outputPoint";
+
+    @Input(INPUT_POINT)
+    SubscribableChannel inputPoint();
+
+    @Output(OUTPUT_POINT)
+    MessageChannel outputPoint();
 }

+ 26 - 0
icss-service/src/main/java/com/diagbot/rabbit/MyReceiver.java

@@ -0,0 +1,26 @@
+package com.diagbot.rabbit;
+
+import com.diagbot.facade.BuriedSomeStatisticalFacade;
+import com.diagbot.util.GsonUtil;
+import com.diagbot.vo.BuriedSomeStatisticalVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.stream.annotation.EnableBinding;
+import org.springframework.cloud.stream.annotation.StreamListener;
+
+/**
+ * @Description: 消费者
+ * @author: gaodm
+ * @time: 2018/8/29 14:02
+ */
+@EnableBinding({ MyProcessor.class })
+public class MyReceiver {
+    @Autowired
+    BuriedSomeStatisticalFacade buriedSomeStatisticalFacade;
+
+    @StreamListener(MyProcessor.INPUT_POINT)
+    public void inputPoint(String message) {
+        System.out.println("Received <" + "数据埋点数据" + ">");
+        BuriedSomeStatisticalVO buriedSomeStatisticalVO = GsonUtil.toObject(message, BuriedSomeStatisticalVO.class);
+        buriedSomeStatisticalFacade.saveBuriedSomeStatistical(buriedSomeStatisticalVO);
+    }
+}

+ 9 - 0
icss-service/src/main/java/com/diagbot/rabbit/MySender.java

@@ -2,6 +2,7 @@ package com.diagbot.rabbit;
 
 import com.diagbot.entity.SysLog;
 import com.diagbot.util.GsonUtil;
+import com.diagbot.vo.BuriedSomeStatisticalVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.cloud.stream.annotation.EnableBinding;
@@ -24,4 +25,12 @@ public class MySender {
     public void outputLogSend(SysLog sysLog) {
         outputLog.send(MessageBuilder.withPayload(GsonUtil.toJson(sysLog)).build());
     }
+
+    @Autowired
+    @Qualifier("outputPoint")
+    MessageChannel outputPoint;
+
+    public void outputPointSend(BuriedSomeStatisticalVO buriedSomeStatisticalVO) {
+        outputPoint.send(MessageBuilder.withPayload(GsonUtil.toJson(buriedSomeStatisticalVO)).build());
+    }
 }

+ 5 - 2
icss-service/src/main/java/com/diagbot/web/BuriedSomeStatisticalController.java

@@ -2,6 +2,7 @@ package com.diagbot.web;
 
 import javax.validation.Valid;
 
+import com.diagbot.rabbit.MySender;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -28,6 +29,8 @@ import io.swagger.annotations.ApiOperation;
 @Api(value = "数据埋点统计API[by:wangfeng]", tags = { "WF——数据埋点统计API" })
 @SuppressWarnings("unchecked")
 public class BuriedSomeStatisticalController {
+	@Autowired
+	MySender mySender;
 
 	@Autowired
 	BuriedSomeStatisticalFacade buriedSomeStatisticalFacade;
@@ -38,9 +41,9 @@ public class BuriedSomeStatisticalController {
 	@Transactional
 	public RespDTO<Boolean> saveBuriedSomeStatisticals(@Valid @RequestBody BuriedSomeStatisticalVO buriedSomeStatisticalVO) {
 
-		boolean res = buriedSomeStatisticalFacade.saveBuriedSomeStatistical(buriedSomeStatisticalVO);
+		mySender.outputPointSend(buriedSomeStatisticalVO);
 
-		return RespDTO.onSuc(res);
+		return RespDTO.onSuc(true);
 	}
 
 }