| | |
| | | |
| | | public void sendMsg(RequestBean requestBean) { |
| | | String chatStr = requestBean.getData().toString(); |
| | | log.info("接收到的消息:{}", chatStr); |
| | | ChatRequest chat = JSONObject.parseObject(chatStr, ChatRequest.class); |
| | | |
| | | Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId()); |
| | | ResponseBean res = ResponseBean.ok(chat); |
| | | chat.setTimestamp(System.currentTimeMillis()); |
| | | res.setType(2); |
| | | channel.writeAndFlush(NettyTools.webSocketJson(res)); |
| | | |
| | |
| | | ResponseBean toRes = ResponseBean.ok(chat); |
| | | res.setType(2); |
| | | targetChannel.writeAndFlush(NettyTools.webSocketJson(toRes)); |
| | | |
| | | chatProducer.sendMsgHistory(chat); |
| | | } else { |
| | | // 在redis中保存用户未在线时,给该用户发送的消息条数 |
| | | String key = AppContants.MSG_NOTICE + chat.getTargetId(); |
| | |
| | | redisUtils.set(key, Integer.parseInt(value) + 1); |
| | | } |
| | | } |
| | | chatProducer.sendMsgHistory(chat); |
| | | } |
| | | } |