648540858
2022-09-22 5e73874880cdfd5b6b99147a0cdd8a6eabcfbf16
src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java
File was renamed from src/main/java/com/genersoft/iot/vmp/service/impl/RedisGbPlayMsgListener.java
@@ -1,4 +1,4 @@
package com.genersoft.iot.vmp.service.impl;
package com.genersoft.iot.vmp.service.redisMsg;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -19,8 +19,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.text.ParseException;
@@ -28,6 +30,7 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
@@ -85,6 +88,14 @@
    @Autowired
    private ZlmHttpHookSubscribe subscribe;
    private boolean taskQueueHandlerRun = false;
    private final ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>();
    @Qualifier("taskExecutor")
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;
    public interface PlayMsgCallback{
        void handler(ResponseSendItemMsg responseSendItemMsg) throws ParseException;
@@ -100,13 +111,20 @@
    @Override
    public void onMessage(Message message, byte[] bytes) {
        JSONObject msgJSON = JSON.parseObject(message.getBody(), JSONObject.class);
        taskQueue.offer(message);
        if (!taskQueueHandlerRun) {
            taskQueueHandlerRun = true;
            taskExecutor.execute(() -> {
                while (!taskQueue.isEmpty()) {
                    Message msg = taskQueue.poll();
                    JSONObject msgJSON = JSON.parseObject(msg.getBody(), JSONObject.class);
        WvpRedisMsg wvpRedisMsg = JSON.toJavaObject(msgJSON, WvpRedisMsg.class);
        if (!userSetting.getServerId().equals(wvpRedisMsg.getToId())) {
            return;
        }
        if (WvpRedisMsg.isRequest(wvpRedisMsg)) {
            logger.info("[收到REDIS通知] 请求: {}", new String(message.getBody()));
                        logger.info("[收到REDIS通知] 请求: {}", new String(msg.getBody()));
            switch (wvpRedisMsg.getCmd()){
                case WvpRedisMsgCmd.GET_SEND_ITEM:
@@ -122,7 +140,7 @@
            }
        }else {
            logger.info("[收到REDIS通知] 回复: {}", new String(message.getBody()));
                        logger.info("[收到REDIS通知] 回复: {}", new String(msg.getBody()));
            switch (wvpRedisMsg.getCmd()){
                case WvpRedisMsgCmd.GET_SEND_ITEM:
@@ -184,6 +202,12 @@
                    break;
            }
        }
                }
                taskQueueHandlerRun = false;
            });
        }