Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize client message #161

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
@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));

Check warning on line 33 in cim-client/src/main/java/com/crossoverjie/cim/client/service/impl/EchoServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

cim-client/src/main/java/com/crossoverjie/cim/client/service/impl/EchoServiceImpl.java#L33

Added line #L33 was not covered by tests
}

@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 @@


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);

Check warning on line 30 in cim-client/src/main/java/com/crossoverjie/cim/client/service/impl/MsgCallBackListener.java

View check run for this annotation

Codecov / codecov/patch

cim-client/src/main/java/com/crossoverjie/cim/client/service/impl/MsgCallBackListener.java#L29-L30

Added lines #L29 - L30 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
@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 @@

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();

Check warning on line 72 in cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java

View check run for this annotation

Codecov / codecov/patch

cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java#L72

Added line #L72 was not covered by tests
for (Map.Entry<Long, CIMServerResVO> cimServerResVoEntry : serverResVoMap.entrySet()) {
Long userId = cimServerResVoEntry.getKey();
CIMServerResVO cimServerResVO = cimServerResVoEntry.getValue();

Check warning on line 75 in cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java

View check run for this annotation

Codecov / codecov/patch

cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java#L74-L75

Added lines #L74 - L75 were not covered by tests
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));

Check warning on line 79 in cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java

View check run for this annotation

Codecov / codecov/patch

cim-forward-route/src/main/java/com/crossoverjie/cim/route/controller/RouteController.java#L79

Added line #L79 was not covered by tests
continue;
}

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

Expand Down