Skip to content

Commit

Permalink
remove unless exception
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Sep 22, 2024
1 parent 5bba820 commit f92dfcf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class RouteController implements RouteApi {
@RequestMapping(value = "groupRoute", method = RequestMethod.POST)
@ResponseBody()
@Override
public BaseResponse<NULLBody> groupRoute(@RequestBody ChatReqVO groupReqVO) throws Exception {
public BaseResponse<NULLBody> groupRoute(@RequestBody ChatReqVO groupReqVO) {
BaseResponse<NULLBody> res = new BaseResponse();

log.info("msg=[{}]", groupReqVO.toString());
Expand Down Expand Up @@ -103,7 +103,7 @@ public BaseResponse<NULLBody> groupRoute(@RequestBody ChatReqVO groupReqVO) thro
@RequestMapping(value = "p2pRoute", method = RequestMethod.POST)
@ResponseBody()
@Override
public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) throws Exception {
public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) {
BaseResponse<NULLBody> res = new BaseResponse();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface AccountService {
* @param sendUserId 发送者的ID
* @throws Exception
*/
void pushMsg(CIMServerResVO cimServerResVO, long sendUserId , ChatReqVO groupReqVO) throws Exception;
void pushMsg(CIMServerResVO cimServerResVO, long sendUserId , ChatReqVO groupReqVO);

/**
* 用户下线
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,31 @@ public CIMServerResVO loadRouteRelatedByUserId(Long userId) {
}

RouteInfo parse = RouteInfoParseUtil.parse(value);
CIMServerResVO cimServerResVO = new CIMServerResVO(parse.getIp(), parse.getCimServerPort(), parse.getHttpPort());
CIMServerResVO cimServerResVO =
new CIMServerResVO(parse.getIp(), parse.getCimServerPort(), parse.getHttpPort());
return cimServerResVO;
}

private void parseServerInfo(Map<Long, CIMServerResVO> routes, String key) {
long userId = Long.valueOf(key.split(":")[1]);
String value = redisTemplate.opsForValue().get(key);
RouteInfo parse = RouteInfoParseUtil.parse(value);
CIMServerResVO cimServerResVO = new CIMServerResVO(parse.getIp(), parse.getCimServerPort(), parse.getHttpPort());
CIMServerResVO cimServerResVO =
new CIMServerResVO(parse.getIp(), parse.getCimServerPort(), parse.getHttpPort());
routes.put(userId, cimServerResVO);
}


@Override
public void pushMsg(CIMServerResVO cimServerResVO, long sendUserId, ChatReqVO groupReqVO) throws Exception {
public void pushMsg(CIMServerResVO cimServerResVO, long sendUserId, ChatReqVO groupReqVO) {
Optional<CIMUserInfo> cimUserInfo = userInfoCacheService.loadUserInfoByUserId(sendUserId);

cimUserInfo.ifPresent(userInfo -> {
String url = "http://" + cimServerResVO.getIp() + ":" + cimServerResVO.getHttpPort();
SendMsgReqVO vo = new SendMsgReqVO(userInfo.getUserName() + ":" + groupReqVO.getMsg(), groupReqVO.getUserId());
try {
serverApi.sendMsg(vo, url);
} catch (Exception e) {
log.error("Error sending message", e);
throw new RuntimeException("Error sending message", e);
}
SendMsgReqVO vo =
new SendMsgReqVO(userInfo.getUserName() + ":" + groupReqVO.getMsg(), groupReqVO.getUserId());
serverApi.sendMsg(vo, url);

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Optional<CIMUserInfo> loadUserInfoByUserId(Long userId) {
//优先从本地缓存获取
CIMUserInfo cimUserInfo = USER_INFO_MAP.get(userId);
if (cimUserInfo != null){
return Optional.ofNullable(cimUserInfo);
return Optional.of(cimUserInfo);
}

//load redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public interface RouteApi {
* @return
* @throws Exception
*/
BaseResponse<NULLBody> groupRoute(ChatReqVO groupReqVO) throws Exception;
BaseResponse<NULLBody> groupRoute(ChatReqVO groupReqVO);

/**
* Point to point chat
* @param p2pRequest
* @return
* @throws Exception
*/
BaseResponse<NULLBody> p2pRoute(P2PReqVO p2pRequest) throws Exception;
BaseResponse<NULLBody> p2pRoute(P2PReqVO p2pRequest);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public interface ServerApi {
* @return
* @throws Exception
*/
BaseResponse<SendMsgResVO> sendMsg(SendMsgReqVO sendMsgReqVO, @DynamicUrl String url) throws Exception;
BaseResponse<SendMsgResVO> sendMsg(SendMsgReqVO sendMsgReqVO, @DynamicUrl String url);
}

0 comments on commit f92dfcf

Please sign in to comment.