Browse Source

增加一个postman发送测试数据的接口

luoguangyi 3 years ago
parent
commit
7a6551e8ee

+ 38 - 0
src/main/java/com/persagy/iottransfer/controller/HelloWorld.java

@@ -0,0 +1,38 @@
+package com.persagy.iottransfer.controller;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.iottransfer.communication.entity.PacketEntity;
+import com.persagy.iottransfer.kafka.KafkaProducer;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+@RestController
+@RequestMapping("test")
+@Slf4j
+public class HelloWorld {
+    @Autowired
+    KafkaProducer kafkaProducer;
+
+    @PostMapping("/")
+    public String world(@RequestBody JSONObject jsonObject) throws Exception {
+        return "hello world!";
+    }
+
+
+    @PostMapping("/sendKafka")
+    public int kafka2(@RequestBody JSONObject jsonObject) throws Exception {
+        String topic = jsonObject.getString("topic");
+        PacketEntity packetEntity = jsonObject.getObject("packetEntity", PacketEntity.class);
+        kafkaProducer.sendMessage(packetEntity,topic);
+        return packetEntity.toString().getBytes(StandardCharsets.UTF_8).length;
+    }
+}
+

+ 2 - 2
src/main/resources/application.yml

@@ -12,10 +12,10 @@ spring:
     #ssl认证,根据情况配置,store-location相关的认证文件对应添加,需要更改
     ssl:
       key-password: test
-      key-store-location: /usr/persagy/iot-transfer/server.keystore.jks
+      key-store-location: /usr/persagy/iot-transfer/config/server.keystore.jks
       key-store-password: test
       key-store-type: JKS
-      trust-store-location: /usr/persagy/iot-transfer/client.truststore.jks
+      trust-store-location: /usr/persagy/iot-transfer/config/client.truststore.jks
       trust-store-password: test
     producer:
       # 发生错误后,消息重发的次数。