瀏覽代碼

放弃消息队列,使用接口。

lighter 3 年之前
父節點
當前提交
f07456d681

+ 21 - 0
src/main/java/thyyxxk/webserver/controller/webosket/SendSocketController.java

@@ -0,0 +1,21 @@
+package thyyxxk.webserver.controller.webosket;
+
+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 thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.entity.dictionary.PureCodeName;
+import thyyxxk.webserver.websocket.WebSocketServer;
+
+@RestController
+@RequestMapping("/socketMessage")
+public class SendSocketController {
+
+    @PassToken
+    @PostMapping("/sendById")
+    public String sendMessageById(@RequestBody PureCodeName msg) {
+        WebSocketServer.sendMessage(msg.getCode(), msg.getName());
+        return "done";
+    }
+}

+ 0 - 27
src/main/java/thyyxxk/webserver/rabbitmq/MsgConsumer.java

@@ -1,27 +0,0 @@
-package thyyxxk.webserver.rabbitmq;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.core.Message;
-import org.springframework.amqp.rabbit.annotation.*;
-import org.springframework.stereotype.Component;
-import thyyxxk.webserver.websocket.WebSocketServer;
-
-import java.nio.charset.StandardCharsets;
-
-/**
- * @author dj
- */
-@Slf4j
-@Component
-public class MsgConsumer {
-
-    @RabbitListener(bindings = {@QueueBinding(value = @Queue(value = RabbitConfig.TOPIC_QUEUE_NAME, durable = "true"),
-                                    exchange = @Exchange(value = RabbitConfig.TOPIC_EXCHANGE, type = "topic"),
-                                    key = RabbitConfig.TOPIC_ROUTING_KEY)})
-    @RabbitHandler
-    public void processTopicMsg(Message message) {
-        String sid = message.getMessageProperties().getReceivedRoutingKey().split("\\.")[1];
-        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
-        WebSocketServer.sendMessage(sid, msg);
-    }
-}

+ 0 - 32
src/main/java/thyyxxk/webserver/rabbitmq/RabbitConfig.java

@@ -1,32 +0,0 @@
-package thyyxxk.webserver.rabbitmq;
-
-import org.springframework.amqp.core.Binding;
-import org.springframework.amqp.core.BindingBuilder;
-import org.springframework.amqp.core.Queue;
-import org.springframework.amqp.core.TopicExchange;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class RabbitConfig {
-    public static final String TOPIC_QUEUE_NAME = "upload_response";
-    public static final String TOPIC_EXCHANGE = "upload_exchange";
-    public static final String TOPIC_ROUTING_KEY = "upload_key.*";
-
-    @Bean
-    public Queue createTopicQueue() {
-        return new Queue(TOPIC_QUEUE_NAME);
-    }
-
-    @Bean
-    TopicExchange defTopicExchange(){
-        return new TopicExchange(TOPIC_EXCHANGE);
-    }
-
-    @Bean
-    Binding bindingTopic() {
-        return BindingBuilder.bind(createTopicQueue()).
-                to(defTopicExchange()).
-                with(TOPIC_ROUTING_KEY);
-    }
-}