|
@@ -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;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|