Browse Source

防止重复数据 入队列

zjs 3 days ago
parent
commit
a1d3771a87

+ 8 - 0
src/main/java/com/cn/esermis/config/MyBatisPlusConfig.java

@@ -1,6 +1,7 @@
1
 package com.cn.esermis.config;
1
 package com.cn.esermis.config;
2
 
2
 
3
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
3
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4
+import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
4
 import org.springframework.context.annotation.Bean;
5
 import org.springframework.context.annotation.Bean;
5
 import org.springframework.context.annotation.Configuration;
6
 import org.springframework.context.annotation.Configuration;
6
 
7
 
@@ -11,4 +12,11 @@ public class MyBatisPlusConfig {
11
         PaginationInterceptor page = new PaginationInterceptor();
12
         PaginationInterceptor page = new PaginationInterceptor();
12
         return page;
13
         return page;
13
     }
14
     }
15
+    @Bean
16
+    public PerformanceInterceptor performanceInterceptor() {
17
+        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
18
+        performanceInterceptor.setWriteInLog(true);
19
+        return performanceInterceptor;
20
+    }
21
+
14
 }
22
 }

+ 5 - 0
src/main/java/com/cn/esermis/netty/BootNettyChannelInboundHandlerAdapter.java

@@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
23
 import java.util.Date;
23
 import java.util.Date;
24
 import java.util.HashMap;
24
 import java.util.HashMap;
25
 import java.util.Map;
25
 import java.util.Map;
26
+import java.util.UUID;
26
 import java.util.concurrent.TimeUnit;
27
 import java.util.concurrent.TimeUnit;
27
 
28
 
28
 @Log4j2
29
 @Log4j2
@@ -225,4 +226,8 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
225
             ctx.channel().close();
226
             ctx.channel().close();
226
         }
227
         }
227
     }
228
     }
229
+
230
+    public static void main(String[] args) {
231
+        System.out.println(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 2));
232
+    }
228
 }
233
 }

+ 4 - 0
src/main/java/com/cn/esermis/server/Consumer.java

@@ -52,6 +52,10 @@ public class Consumer {
52
             }else{
52
             }else{
53
                 tolot++;
53
                 tolot++;
54
                 int finalTolot = tolot;
54
                 int finalTolot = tolot;
55
+//                System.out.println("消费消息------------:第("+ finalTolot+")条");
56
+//                JSONObject jsonObject = (JSONObject) JSON.toJSON(message);
57
+//                monitorBusiness.inboundOperations(jsonObject);
58
+
55
                 executorService.submit(new Runnable() {
59
                 executorService.submit(new Runnable() {
56
                     @Override
60
                     @Override
57
                     public void run() {
61
                     public void run() {

+ 8 - 4
src/main/resources/application.yml

@@ -56,18 +56,18 @@ spring:
56
         # 比如我的scs_product_1  和 scs_product_2  那就写scs_product好区分
56
         # 比如我的scs_product_1  和 scs_product_2  那就写scs_product好区分
57
         # 当执行sql中出现scs_product,sharding-jdbc会将其操作到对应的表
57
         # 当执行sql中出现scs_product,sharding-jdbc会将其操作到对应的表
58
         air_monitor_minute_record:
58
         air_monitor_minute_record:
59
-          actual-data-nodes: scy.air_monitor_minute_record_$->{1..2}
59
+          actual-data-nodes: scy.air_monitor_minute_record_$->{0..1}
60
           # 指定主键生成策略为雪花id,全局主键
60
           # 指定主键生成策略为雪花id,全局主键
61
           key-generator:
61
           key-generator:
62
             column: id
62
             column: id
63
-            type: SNOWFLAKE
63
+            type: UUID
64
           #指定scs_product表的分片策略,  分片键和分片算法 用于计算真正的表名
64
           #指定scs_product表的分片策略,  分片键和分片算法 用于计算真正的表名
65
           table-strategy:
65
           table-strategy:
66
             inline:
66
             inline:
67
               # 偶数进到scs_product_1  奇数进到scs_product_2
67
               # 偶数进到scs_product_1  奇数进到scs_product_2
68
               # 对于根据分片字段为条件的,会先判断是否涉及两张表,
68
               # 对于根据分片字段为条件的,会先判断是否涉及两张表,
69
               # 如何是两张表则会两个表都查,如果只涉及单表,则只查询一张表。
69
               # 如何是两张表则会两个表都查,如果只涉及单表,则只查询一张表。
70
-              algorithm-expression: air_monitor_minute_record_$->{id % 2 + 1}
70
+              algorithm-expression: air_monitor_minute_record_$->{new java.util.Random().nextInt(9) % 2}
71
               # 指定分片键为PRODUCT_ID
71
               # 指定分片键为PRODUCT_ID
72
               sharding-column: id
72
               sharding-column: id
73
   # Redis 配置
73
   # Redis 配置
@@ -90,4 +90,8 @@ spring:
90
 mybatis-plus:
90
 mybatis-plus:
91
   mapper-locations: classpath:static/**/*.xml
91
   mapper-locations: classpath:static/**/*.xml
92
   configuration:
92
   configuration:
93
-    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl # 指定 MyBatis 使用 SLF4J 日志实现
93
+    call-setters-on-nulls: on
94
+    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl # 指定 MyBatis 使用 SLF4J 日志实现
95
+logging:
96
+  level:
97
+    com.example.classroomrealtimefeedback.mapper: debug