| | |
| | | |
| | | import java.io.IOException; |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | import java.util.concurrent.TimeoutException; |
| | | |
| | | import javax.websocket.OnClose; |
| | | import javax.websocket.OnError; |
| | |
| | | |
| | | private String regionCode; |
| | | |
| | | private Connection connection; |
| | | |
| | | private Channel channel; |
| | | |
| | | // 存放session的集合,很重要!! |
| | | private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>(); |
| | | |
| | |
| | | factory.setUsername("guest"); |
| | | factory.setPassword("guest_pass"); |
| | | String routingKey = orgId+".*"; |
| | | Connection connection = factory.newConnection(); |
| | | Channel channel = connection.createChannel(); |
| | | connection = factory.newConnection(); |
| | | channel = connection.createChannel(); |
| | | //声明队列,主要为了防止消息接收者先运行此程序,队列还不存在时创建队列。 |
| | | channel.queueDeclare(QUEUE_NAME, false, false, true, null); |
| | | channel.queueBind(QUEUE_NAME,"screens_data",routingKey); |
| | |
| | | public void onClose() { |
| | | /**从安全Set中 移除当前连接对象*/ |
| | | webSocketSet.remove(this); |
| | | try { |
| | | channel.close(); |
| | | connection.close(); |
| | | }catch (IOException | TimeoutException e){ |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @OnMessage |