|
|
@@ -0,0 +1,28 @@
|
|
|
+package org.ruoyi.chat.controller.chat;
|
|
|
+
|
|
|
+import org.apache.rocketmq.client.producer.SendResult;
|
|
|
+import org.ruoyi.chat.service.RocketMQService;
|
|
|
+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;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/RocketMQ")
|
|
|
+public class MessageController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RocketMQService rocketMQService;
|
|
|
+
|
|
|
+ @PostMapping("/send")
|
|
|
+
|
|
|
+ public String sendMessageToRocketMQ(@RequestBody String message) {
|
|
|
+ try {
|
|
|
+ SendResult result = rocketMQService.sendMessage(message);
|
|
|
+ return "消息发送成功: " + result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "消息发送失败: " + e.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|