更新Websocket以及rabbitMQ关闭逻辑
| | |
| | | */ |
| | | /*改动范围start-------------------------------------------------------------------------*/ |
| | | list.remove(0); |
| | | if (list.size() == 23) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); |
| | | //获取全格式时间yyyy-MM-dd HH:mm:ss |
| | |
| | | datas.put("time",time1); |
| | | list.add(datas); |
| | | } |
| | | } |
| | | /*改动范围end-------------------------------------------------------------------------*/ |
| | | |
| | | /*改动范围end-------------------------------------------------------------------------*/ |
| | | |
| | | for (Map<String, Object> map : list) { |
| | | String time = map.get("time").toString(); |
| | |
| | | |
| | | public static void closeConnectionChannel(Connection connection, Channel channel){ |
| | | try{ |
| | | if(channel!=null) |
| | | if(channel!=null&&channel.isOpen()) |
| | | channel.close(); |
| | | if(connection!=null) |
| | | if(connection!=null&&connection.isOpen()) |
| | | connection.close(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | |
| | | channel.basicConsume(queue, false, new DefaultConsumer(channel) { |
| | | @Override |
| | | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { |
| | | //对从MQ中取出的数据做转换,并且发送风速到客户端 |
| | | Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); |
| | | Device device = deviceService.getDeviceByMac(mac,false); |
| | | sendDeviceInfo(message, device); |
| | | //手动确认 |
| | | channel.basicAck(envelope.getDeliveryTag(), true); |
| | | //判断socket是否已经断开 |
| | | if (!webSocketMap.containsKey(accountId)) { |
| | | try{ |
| | | //对从MQ中取出的数据做转换,并且发送风速到客户端 |
| | | Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); |
| | | Device device = deviceService.getDeviceByMac(mac,false); |
| | | sendDeviceInfo(message, device); |
| | | //手动确认 |
| | | channel.basicAck(envelope.getDeliveryTag(), true); |
| | | //判断socket是否已经断开 |
| | | if (!webSocketMap.containsKey(accountId)) { |
| | | RabbitMQUtils.closeConnectionChannel(connection, channel); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | RabbitMQUtils.closeConnectionChannel(connection, channel); |
| | | } |
| | | } |
| | |
| | | channel.basicConsume(queue, false, new DefaultConsumer(channel) { |
| | | @Override |
| | | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { |
| | | //对从MQ中取出的数据做转换,并且发送风速到客户端 |
| | | Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); |
| | | sendWindInfo(message); |
| | | try{ |
| | | //对从MQ中取出的数据做转换,并且发送风速到客户端 |
| | | Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); |
| | | sendWindInfo(message); |
| | | |
| | | //判断是否接收到客户端发送的mac,如果接收到则返回指定mac设备信息 |
| | | if(mac!=null&&(!mac.equals(0))) |
| | | sendDeviceInfo(message,deviceMap); |
| | | //判断是否接收到客户端发送的mac,如果接收到则返回指定mac设备信息 |
| | | if(mac!=null&&(!mac.equals(0))) |
| | | sendDeviceInfo(message,deviceMap); |
| | | |
| | | //手动确认 |
| | | channel.basicAck(envelope.getDeliveryTag(), true); |
| | | //手动确认 |
| | | channel.basicAck(envelope.getDeliveryTag(), true); |
| | | |
| | | //判断socket是否已经断开 |
| | | if (!webSocketMap.containsKey(accountId)) { |
| | | RabbitMQUtils.closeConnectionChannel(connection, channel); |
| | | } |
| | | //判断socket是否已经断开 |
| | | if (!webSocketMap.containsKey(accountId)) { |
| | | RabbitMQUtils.closeConnectionChannel(connection, channel); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | RabbitMQUtils.closeConnectionChannel(connection, channel); |
| | | } |
| | | } |
| | | }); |
| | | } catch (IOException e) { |