im分布式测试方案-单机测试
This commit is contained in:
parent
023bd790df
commit
4ce40ede17
@ -34,6 +34,10 @@ public class DistributedMessageService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息给用户
|
* 发送消息给用户
|
||||||
|
* @param targetUserId 目标用户就是account的id
|
||||||
|
* @param message
|
||||||
|
* @param userSessions
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean sendToUser(String targetUserId, SendVO message, ConcurrentHashMap<String, List<WebSocketSession>> userSessions) {
|
public boolean sendToUser(String targetUserId, SendVO message, ConcurrentHashMap<String, List<WebSocketSession>> userSessions) {
|
||||||
log.info("targetUserId{},message:{}", targetUserId, message);
|
log.info("targetUserId{},message:{}", targetUserId, message);
|
||||||
@ -46,10 +50,10 @@ public class DistributedMessageService {
|
|||||||
|
|
||||||
if (isCurrentServer(targetServer)) {
|
if (isCurrentServer(targetServer)) {
|
||||||
// 用户在当前服务器,直接发送
|
// 用户在当前服务器,直接发送
|
||||||
return localSessionManager.sendToUser(targetUserId, message,userSessions);
|
return localSessionManager.sendToUser(message.getToid(), message,userSessions);
|
||||||
} else {
|
} else {
|
||||||
// 用户在其他服务器,通过RabbitMQ转发
|
// 用户在其他服务器,通过RabbitMQ转发
|
||||||
forwardToUser(targetServer, targetUserId, message);
|
forwardToUser(targetServer, message.getToid(), message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,10 @@ public class LocalSessionManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息给用户
|
* 发送消息给用户
|
||||||
|
* @param userId session的id
|
||||||
|
* @param message
|
||||||
|
* @param userSession
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean sendToUser(String userId, SendVO message,ConcurrentHashMap<String, List<WebSocketSession>> userSession) {
|
public boolean sendToUser(String userId, SendVO message,ConcurrentHashMap<String, List<WebSocketSession>> userSession) {
|
||||||
if (userId == null || message == null) {
|
if (userId == null || message == null) {
|
||||||
|
|||||||
@ -130,7 +130,7 @@ public class MallsuiteImSocketHandler implements WebSocketHandler {
|
|||||||
chat.setMsg(msg);
|
chat.setMsg(msg);
|
||||||
chat.setType("friend");
|
chat.setType("friend");
|
||||||
chat.setCreate_date(new Date());
|
chat.setCreate_date(new Date());
|
||||||
boolean isSuccess = distributedMessageService.sendToUser(receiver, sendVO,localSessionManager.getUserSessions());
|
boolean isSuccess = distributedMessageService.sendToUser(String.valueOf(toUserId), sendVO,localSessionManager.getUserSessions());
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
chat.setStatus("1");
|
chat.setStatus("1");
|
||||||
} else {
|
} else {
|
||||||
@ -140,7 +140,7 @@ public class MallsuiteImSocketHandler implements WebSocketHandler {
|
|||||||
sendVO.setMsg_type("text");
|
sendVO.setMsg_type("text");
|
||||||
sendVO.setMessage_length("0");
|
sendVO.setMessage_length("0");
|
||||||
sendVO.setId(to.getId());
|
sendVO.setId(to.getId());
|
||||||
distributedMessageService.sendToUser(sender, sendVO,localSessionManager.getUserSessions());
|
distributedMessageService.sendToUser(String.valueOf(toUserId), sendVO,localSessionManager.getUserSessions());
|
||||||
chat.setStatus("0");
|
chat.setStatus("0");
|
||||||
}
|
}
|
||||||
chatHistoryService.saveNew(chat);
|
chatHistoryService.saveNew(chat);
|
||||||
|
|||||||
@ -820,6 +820,10 @@ public class SnsUserMessageServiceImpl extends BaseServiceImpl<SnsUserMessageMap
|
|||||||
}
|
}
|
||||||
result.put("message_id", data.getMessage_id());
|
result.put("message_id", data.getMessage_id());
|
||||||
result.put("message_other_id", other.getMessage_id());
|
result.put("message_other_id", other.getMessage_id());
|
||||||
|
Map user_info=new HashMap();
|
||||||
|
user_info.put("user_id",user_id);
|
||||||
|
user_info.put("user_nickname",user.getUser_nickname());
|
||||||
|
result.put("user_info",user_info);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user