package xin.merlin.myplayerbackend.utils.websocket; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import xin.merlin.myplayerbackend.config.RabbitMQConfig; import xin.merlin.myplayerbackend.utils.websocket.command.CommandDispatcher; import xin.merlin.myplayerbackend.utils.websocket.command.CommandDispatcherVideo; @Slf4j @Component @RequiredArgsConstructor public class WebSocketMessageConsumer { private final OnlineWebSocketSessionManager sessionManager; private final CommandDispatcher commandDispatcher; private final CommandDispatcherVideo commandDispatcherVideo; @RabbitListener(queues = RabbitMQConfig.WS_MESSAGE_QUEUE) public void onMessage(String json) { try { JSONObject msg = JSON.parseObject(json); commandDispatcher.dispatch(msg); } catch (Exception e) { log.info(e.getMessage()); } } @RabbitListener(queues = RabbitMQConfig.WS_VIDEO_QUEUE) public void onVideoMessage(String json) { try { JSONObject msg = JSON.parseObject(json); commandDispatcherVideo.dispatch(msg); System.out.println("sending video message"); } catch (Exception e) { log.info(e.getMessage()); } } }