|
@@ -1,13 +1,17 @@
|
|
|
package com.macro.mall.tiny.modules.business.service;
|
|
|
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.springframework.data.redis.connection.Message;
|
|
|
import org.springframework.data.redis.connection.MessageListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.websocket.Session;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
@@ -31,20 +35,19 @@ public class RedisSubscribeListener implements MessageListener {
|
|
|
*/
|
|
|
@Override
|
|
|
public void onMessage(Message message, byte[] bytes) {
|
|
|
- String msg = new String(message.getBody());
|
|
|
+ String msg = JSON.parseObject(message.getBody(), String.class);
|
|
|
log.debug("[{}]主题发布:{}", new String(bytes), msg);
|
|
|
- String deviceMac = new JSONObject(msg).getStr("deviceMac");
|
|
|
- System.out.println(deviceMac);
|
|
|
-// if (session != null && session.isOpen()) {
|
|
|
-// if (!sensorMacSet.contains(deviceMac)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// try {
|
|
|
-// session.getBasicRemote().sendText(msg);
|
|
|
-// } catch (IOException e) {
|
|
|
-// log.error("[redis监听器]发布消息异常:", e);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ String deviceMac = JSON.parseObject(msg).getString("deviceMac");
|
|
|
+ if (session != null && session.isOpen()) {
|
|
|
+ if (!sensorMacSet.contains(deviceMac)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ session.getBasicRemote().sendText(msg);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("[redis监听器]发布消息异常:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Session getSession() {
|