From b534e3bd25610bde0b7dc51306660365542e318d Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Tue, 07 Jul 2020 10:08:15 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/webSocketServer/WebSocketServer.java | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/moral/webSocketServer/WebSocketServer.java b/src/main/java/com/moral/webSocketServer/WebSocketServer.java
index e119744..46b26d4 100644
--- a/src/main/java/com/moral/webSocketServer/WebSocketServer.java
+++ b/src/main/java/com/moral/webSocketServer/WebSocketServer.java
@@ -1,8 +1,10 @@
package com.moral.webSocketServer;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.TimeoutException;
import javax.websocket.OnClose;
import javax.websocket.OnError;
@@ -12,7 +14,9 @@
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
-import com.moral.service.MonitorPointService;
+import com.moral.common.util.ParameterUtils;
+import com.moral.entity.Device;
+import com.moral.service.DeviceService;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
@@ -30,7 +34,7 @@
@Component
public class WebSocketServer {
- public static MonitorPointService monitorPointService;
+ public static DeviceService deviceService;
// ������������������������������������������������������������������������������
private Session session;
@@ -38,6 +42,8 @@
private String orgId;
private String accountId;
+
+ private String regionCode;
private Connection connection;
@@ -57,9 +63,16 @@
//������������������������������������������������
webSocketSet.add(this);
int flag = param.indexOf("&");
+ int regionCodeIndex = param.indexOf("_");
orgId = param.substring(0, flag);
- accountId = param.substring(flag + 1);
- String QUEUE_NAME = "deviceInfo_"+accountId;
+ accountId = param.substring(flag + 1,regionCodeIndex);
+ regionCode = param.substring(regionCodeIndex + 1);
+ String QUEUE_NAME = "deviceInfo_" + accountId;
+ Map<String, Object> paramMap = new HashMap<String, Object>();
+ paramMap.put("orgId", orgId);
+ paramMap.put("regionCode", regionCode);
+ ParameterUtils.getRegionType4RegionCode(paramMap);
+ List<Device> deviceList = deviceService.queryDevice(paramMap);
try {
//������������������������������������������������
ConnectionFactory factory = new ConnectionFactory();
@@ -68,13 +81,15 @@
factory.setPort(5672);
factory.setUsername("guest");
factory.setPassword("guest_pass");
- String routingKey = orgId+".*";
+ String routingKey;
connection = factory.newConnection();
channel = connection.createChannel();
//���������������������������������������������������������������������������������������������������������
channel.queueDeclare(QUEUE_NAME, false, false, true, null);
- channel.queueBind(QUEUE_NAME,"screens_data",routingKey);
-
+ for (Device d : deviceList) {
+ routingKey = orgId + "." + d.getMac();
+ channel.queueBind(QUEUE_NAME, "screens_data", routingKey);
+ }
//���������������������
QueueingConsumer consumer = new QueueingConsumer(channel);
//������������������
@@ -86,7 +101,7 @@
String message = new String(delivery.getBody());
sendMessage(message);
}
- }catch (Exception e){
+ } catch (Exception e) {
log.error(e.getMessage());
}
}
@@ -99,9 +114,8 @@
/**���������Set��� ������������������������*/
webSocketSet.remove(this);
try {
- channel.close();
connection.close();
- }catch (IOException | TimeoutException e){
+ } catch (IOException e) {
log.error(e.getMessage());
}
}
--
Gitblit v1.8.0