Quellcode durchsuchen

kafka协议处理

xucaiqin vor 1 Jahr
Ursprung
Commit
366223aaa8

+ 4 - 0
iot-module/iot-module-data/iot-module-data-biz/pom.xml

@@ -80,6 +80,10 @@
             <groupId>com.middle.platform</groupId>
             <artifactId>iot-starter-rabbitmq</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-starter-kafka</artifactId>
+        </dependency>
     </dependencies>
     <build>
         <!-- 设置构建的 jar 包名 -->

+ 20 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/java/com/middle/platform/data/biz/service/kafka/KafkaService.java

@@ -0,0 +1,20 @@
+package com.middle.platform.data.biz.service.kafka;
+
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author xucaiqin
+ * @date 2024-04-17 15:23:05
+ */
+@Component
+public class KafkaService {
+
+    @KafkaListener(topics = {"iot.data"})
+    public void receive(ConsumerRecord<String, Object> object) {
+        System.out.println("receive:" + object);
+
+
+    }
+}

+ 4 - 0
iot-module/iot-module-data/iot-module-data-biz/src/main/resources/bootstrap-local.yaml

@@ -16,3 +16,7 @@ spring:
           - data-id: common.yaml
             group: common
             refresh: true
+  kafka:
+    bootstrap-servers: localhost:9092
+    consumer:
+      group-id: iot