Skip to content

Commit

Permalink
Merge pull request #161 from crossoverJie/optimize-client-msg
Browse files Browse the repository at this point in the history
Optimize client message
  • Loading branch information
crossoverJie authored Sep 30, 2024
2 parents 9c293c1 + 5bfad6c commit 77715b9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected void channelRead0(ChannelHandlerContext ctx, CIMResponseProto.CIMResPr

if (msg.getType() != Constants.CommandType.PING) {
// callback
ClientImpl.getClient().getConf().getEvent().info(msg.getResMsg());
ClientImpl.getClient().getConf().getCallbackThreadPool().execute(() -> {
ClientImpl.getClient().getConf().getMessageListener().received(ClientImpl.getClient(), msg.getResMsg());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.crossoverjie.cim.client.sdk.io.backoff;

import java.util.concurrent.TimeUnit;

/**
* @author:qjj
* @create: 2024-09-21 12:22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Client buildClient(@Qualifier("callBackThreadPool") ThreadPoolExecutor ca
.event(event)
.reconnectCheck(client -> !shutDownSign.checkStatus())
.okHttpClient(okHttpClient)
.messageListener(new MsgCallBackListener(msgLogger))
.messageListener(new MsgCallBackListener(msgLogger, event))
.callbackThreadPool(callbackThreadPool)
.backoffStrategy(new RandomBackoff())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.crossoverjie.cim.client.config.AppConfiguration;
import com.crossoverjie.cim.client.sdk.Client;
import com.crossoverjie.cim.client.sdk.Event;
import com.crossoverjie.cim.client.service.MsgLogger;
import com.vdurmont.emoji.EmojiParser;
import jakarta.annotation.Resource;
import java.time.LocalDate;
Expand All @@ -24,9 +25,12 @@ public class EchoServiceImpl implements Event {
@Resource
private AppConfiguration appConfiguration;

@Resource
private MsgLogger msgLogger;

@Override
public void debug(String msg, Object... replace) {
info(String.format("Debug[%s]", msg), replace);
msgLogger.log(String.format("Debug[%s]", msg));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crossoverjie.cim.client.service.impl;

import com.crossoverjie.cim.client.sdk.Client;
import com.crossoverjie.cim.client.sdk.Event;
import com.crossoverjie.cim.client.sdk.io.MessageListener;
import com.crossoverjie.cim.client.service.MsgLogger;

Expand All @@ -15,14 +16,17 @@ public class MsgCallBackListener implements MessageListener {


private final MsgLogger msgLogger;
private final Event event;

public MsgCallBackListener(MsgLogger msgLogger) {
public MsgCallBackListener(MsgLogger msgLogger, Event event) {
this.msgLogger = msgLogger;
this.event = event;
}


@Override
public void received(Client client, String msg) {
msgLogger.log(msg);
this.msgLogger.log(msg);
this.event.info(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class RouteController implements RouteApi {
@Resource
private MetaStore metaStore;

@Autowired
@Resource
private AccountService accountService;

@Autowired
@Resource
private UserInfoCacheService userInfoCacheService;

@Autowired
@Resource
private CommonBizService commonBizService;

@Resource
Expand All @@ -69,19 +69,18 @@ public BaseResponse<NULLBody> groupRoute(@RequestBody ChatReqVO groupReqVO) {

log.info("msg=[{}]", groupReqVO.toString());

//获取所有的推送列表
Map<Long, CIMServerResVO> serverResVOMap = accountService.loadRouteRelated();
for (Map.Entry<Long, CIMServerResVO> cimServerResVOEntry : serverResVOMap.entrySet()) {
Long userId = cimServerResVOEntry.getKey();
CIMServerResVO cimServerResVO = cimServerResVOEntry.getValue();
Map<Long, CIMServerResVO> serverResVoMap = accountService.loadRouteRelated();
for (Map.Entry<Long, CIMServerResVO> cimServerResVoEntry : serverResVoMap.entrySet()) {
Long userId = cimServerResVoEntry.getKey();
CIMServerResVO cimServerResVO = cimServerResVoEntry.getValue();
if (userId.equals(groupReqVO.getUserId())) {
//过滤掉自己
// Skip the sender
Optional<CIMUserInfo> cimUserInfo = userInfoCacheService.loadUserInfoByUserId(groupReqVO.getUserId());
cimUserInfo.ifPresent(userInfo -> log.warn("过滤掉了发送者 userId={}", userInfo.toString()));
cimUserInfo.ifPresent(userInfo -> log.warn("skip send user userId={}", userInfo));
continue;
}

//推送消息
// Push message
ChatReqVO chatVO = new ChatReqVO(userId, groupReqVO.getMsg());
accountService.pushMsg(cimServerResVO, groupReqVO.getUserId(), chatVO);

Expand Down

0 comments on commit 77715b9

Please sign in to comment.