|
|
@@ -0,0 +1,67 @@
|
|
|
+package com.middle.platform.demo.controller;
|
|
|
+
|
|
|
+import com.middle.platform.demo.service.KafkaService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xucaiqin
|
|
|
+ * @date 2024-04-02 15:17:47
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/kafka")
|
|
|
+public class TestController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private KafkaService kafkaService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送文本消息
|
|
|
+ *
|
|
|
+ * @param msg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/send/{msg}")
|
|
|
+ public String send(@PathVariable String msg) {
|
|
|
+ kafkaService.tet(msg);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 发送JSON数据
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @GetMapping("/send2")
|
|
|
+// public String send2() {
|
|
|
+// Message message = new Message();
|
|
|
+// message.setId(System.currentTimeMillis());
|
|
|
+// message.setMsg("生产者发送消息到topic1: " + UUID.getUUID32());
|
|
|
+// message.setSendTime(new Date());
|
|
|
+//
|
|
|
+// String value = JSON.toJSONString(message);
|
|
|
+// log.info("生产者发送消息到topic1 message = {}", value);
|
|
|
+//
|
|
|
+// kafkaService.send(kafkaConfiguration.getMyTopic1(),value);
|
|
|
+// return value;
|
|
|
+// }
|
|
|
+// /**
|
|
|
+// * 发送JSON数据
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @GetMapping("/send3")
|
|
|
+// public String send3() {
|
|
|
+// Message message = new Message();
|
|
|
+// message.setId(System.currentTimeMillis());
|
|
|
+// message.setMsg("生产者发送消息到topic2: " + UUID.getUUID32());
|
|
|
+// message.setSendTime(new Date());
|
|
|
+//
|
|
|
+// String value = JSON.toJSONString(message);
|
|
|
+// log.info("生产者发送消息到topic2 message = {}", value);
|
|
|
+//
|
|
|
+// kafkaService.send(kafkaConfiguration.getMyTopic2(),value);
|
|
|
+// return value;
|
|
|
+// }
|
|
|
+}
|